<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.6.6" />
<title>Avro C</title>
<style type="text/css">
/* Shared CSS for AsciiDoc xhtml11 and html5 backends */

/* Default font. */
body {
  font-family: Georgia,serif;
}

/* Title font. */
h1, h2, h3, h4, h5, h6,
div.title, caption.title,
thead, p.table.header,
#toctitle,
#author, #revnumber, #revdate, #revremark,
#footer {
  font-family: Arial,Helvetica,sans-serif;
}

body {
  margin: 1em 5% 1em 5%;
}

a {
  color: blue;
  text-decoration: underline;
}
a:visited {
  color: fuchsia;
}

em {
  font-style: italic;
  color: navy;
}

strong {
  font-weight: bold;
  color: #083194;
}

h1, h2, h3, h4, h5, h6 {
  color: #527bbd;
  margin-top: 1.2em;
  margin-bottom: 0.5em;
  line-height: 1.3;
}

h1, h2, h3 {
  border-bottom: 2px solid silver;
}
h2 {
  padding-top: 0.5em;
}
h3 {
  float: left;
}
h3 + * {
  clear: left;
}
h5 {
  font-size: 1.0em;
}

div.sectionbody {
  margin-left: 0;
}

hr {
  border: 1px solid silver;
}

p {
  margin-top: 0.5em;
  margin-bottom: 0.5em;
}

ul, ol, li > p {
  margin-top: 0;
}
ul > li     { color: #aaa; }
ul > li > * { color: black; }

pre {
  padding: 0;
  margin: 0;
}

#author {
  color: #527bbd;
  font-weight: bold;
  font-size: 1.1em;
}
#email {
}
#revnumber, #revdate, #revremark {
}

#footer {
  font-size: small;
  border-top: 2px solid silver;
  padding-top: 0.5em;
  margin-top: 4.0em;
}
#footer-text {
  float: left;
  padding-bottom: 0.5em;
}
#footer-badges {
  float: right;
  padding-bottom: 0.5em;
}

#preamble {
  margin-top: 1.5em;
  margin-bottom: 1.5em;
}
div.imageblock, div.exampleblock, div.verseblock,
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
div.admonitionblock {
  margin-top: 1.0em;
  margin-bottom: 1.5em;
}
div.admonitionblock {
  margin-top: 2.0em;
  margin-bottom: 2.0em;
  margin-right: 10%;
  color: #606060;
}

div.content { /* Block element content. */
  padding: 0;
}

/* Block element titles. */
div.title, caption.title {
  color: #527bbd;
  font-weight: bold;
  text-align: left;
  margin-top: 1.0em;
  margin-bottom: 0.5em;
}
div.title + * {
  margin-top: 0;
}

td div.title:first-child {
  margin-top: 0.0em;
}
div.content div.title:first-child {
  margin-top: 0.0em;
}
div.content + div.title {
  margin-top: 0.0em;
}

div.sidebarblock > div.content {
  background: #ffffee;
  border: 1px solid #dddddd;
  border-left: 4px solid #f0f0f0;
  padding: 0.5em;
}

div.listingblock > div.content {
  border: 1px solid #dddddd;
  border-left: 5px solid #f0f0f0;
  background: #f8f8f8;
  padding: 0.5em;
}

div.quoteblock, div.verseblock {
  padding-left: 1.0em;
  margin-left: 1.0em;
  margin-right: 10%;
  border-left: 5px solid #f0f0f0;
  color: #888;
}

div.quoteblock > div.attribution {
  padding-top: 0.5em;
  text-align: right;
}

div.verseblock > pre.content {
  font-family: inherit;
  font-size: inherit;
}
div.verseblock > div.attribution {
  padding-top: 0.75em;
  text-align: left;
}
/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
div.verseblock + div.attribution {
  text-align: left;
}

div.admonitionblock .icon {
  vertical-align: top;
  font-size: 1.1em;
  font-weight: bold;
  text-decoration: underline;
  color: #527bbd;
  padding-right: 0.5em;
}
div.admonitionblock td.content {
  padding-left: 0.5em;
  border-left: 3px solid #dddddd;
}

div.exampleblock > div.content {
  border-left: 3px solid #dddddd;
  padding-left: 0.5em;
}

div.imageblock div.content { padding-left: 0; }
span.image img { border-style: none; }
a.image:visited { color: white; }

dl {
  margin-top: 0.8em;
  margin-bottom: 0.8em;
}
dt {
  margin-top: 0.5em;
  margin-bottom: 0;
  font-style: normal;
  color: navy;
}
dd > *:first-child {
  margin-top: 0.1em;
}

ul, ol {
    list-style-position: outside;
}
ol.arabic {
  list-style-type: decimal;
}
ol.loweralpha {
  list-style-type: lower-alpha;
}
ol.upperalpha {
  list-style-type: upper-alpha;
}
ol.lowerroman {
  list-style-type: lower-roman;
}
ol.upperroman {
  list-style-type: upper-roman;
}

div.compact ul, div.compact ol,
div.compact p, div.compact p,
div.compact div, div.compact div {
  margin-top: 0.1em;
  margin-bottom: 0.1em;
}

tfoot {
  font-weight: bold;
}
td > div.verse {
  white-space: pre;
}

div.hdlist {
  margin-top: 0.8em;
  margin-bottom: 0.8em;
}
div.hdlist tr {
  padding-bottom: 15px;
}
dt.hdlist1.strong, td.hdlist1.strong {
  font-weight: bold;
}
td.hdlist1 {
  vertical-align: top;
  font-style: normal;
  padding-right: 0.8em;
  color: navy;
}
td.hdlist2 {
  vertical-align: top;
}
div.hdlist.compact tr {
  margin: 0;
  padding-bottom: 0;
}

.comment {
  background: yellow;
}

.footnote, .footnoteref {
  font-size: 0.8em;
}

span.footnote, span.footnoteref {
  vertical-align: super;
}

#footnotes {
  margin: 20px 0 20px 0;
  padding: 7px 0 0 0;
}

#footnotes div.footnote {
  margin: 0 0 5px 0;
}

#footnotes hr {
  border: none;
  border-top: 1px solid silver;
  height: 1px;
  text-align: left;
  margin-left: 0;
  width: 20%;
  min-width: 100px;
}

div.colist td {
  padding-right: 0.5em;
  padding-bottom: 0.3em;
  vertical-align: top;
}
div.colist td img {
  margin-top: 0.3em;
}

@media print {
  #footer-badges { display: none; }
}

#toc {
  margin-bottom: 2.5em;
}

#toctitle {
  color: #527bbd;
  font-size: 1.1em;
  font-weight: bold;
  margin-top: 1.0em;
  margin-bottom: 0.1em;
}

div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
  margin-top: 0;
  margin-bottom: 0;
}
div.toclevel2 {
  margin-left: 2em;
  font-size: 0.9em;
}
div.toclevel3 {
  margin-left: 4em;
  font-size: 0.9em;
}
div.toclevel4 {
  margin-left: 6em;
  font-size: 0.9em;
}

span.aqua { color: aqua; }
span.black { color: black; }
span.blue { color: blue; }
span.fuchsia { color: fuchsia; }
span.gray { color: gray; }
span.green { color: green; }
span.lime { color: lime; }
span.maroon { color: maroon; }
span.navy { color: navy; }
span.olive { color: olive; }
span.purple { color: purple; }
span.red { color: red; }
span.silver { color: silver; }
span.teal { color: teal; }
span.white { color: white; }
span.yellow { color: yellow; }

span.aqua-background { background: aqua; }
span.black-background { background: black; }
span.blue-background { background: blue; }
span.fuchsia-background { background: fuchsia; }
span.gray-background { background: gray; }
span.green-background { background: green; }
span.lime-background { background: lime; }
span.maroon-background { background: maroon; }
span.navy-background { background: navy; }
span.olive-background { background: olive; }
span.purple-background { background: purple; }
span.red-background { background: red; }
span.silver-background { background: silver; }
span.teal-background { background: teal; }
span.white-background { background: white; }
span.yellow-background { background: yellow; }

span.big { font-size: 2em; }
span.small { font-size: 0.6em; }

span.underline { text-decoration: underline; }
span.overline { text-decoration: overline; }
span.line-through { text-decoration: line-through; }


/*
 * xhtml11 specific
 *
 * */

tt {
  font-family: monospace;
  font-size: inherit;
  color: navy;
}

div.tableblock {
  margin-top: 1.0em;
  margin-bottom: 1.5em;
}
div.tableblock > table {
  border: 3px solid #527bbd;
}
thead, p.table.header {
  font-weight: bold;
  color: #527bbd;
}
p.table {
  margin-top: 0;
}
/* Because the table frame attribute is overriden by CSS in most browsers. */
div.tableblock > table[frame="void"] {
  border-style: none;
}
div.tableblock > table[frame="hsides"] {
  border-left-style: none;
  border-right-style: none;
}
div.tableblock > table[frame="vsides"] {
  border-top-style: none;
  border-bottom-style: none;
}


/*
 * html5 specific
 *
 * */

.monospaced {
  font-family: monospace;
  font-size: inherit;
  color: navy;
}

table.tableblock {
  margin-top: 1.0em;
  margin-bottom: 1.5em;
}
thead, p.tableblock.header {
  font-weight: bold;
  color: #527bbd;
}
p.tableblock {
  margin-top: 0;
}
table.tableblock {
  border-width: 3px;
  border-spacing: 0px;
  border-style: solid;
  border-color: #527bbd;
  border-collapse: collapse;
}
th.tableblock, td.tableblock {
  border-width: 1px;
  padding: 4px;
  border-style: solid;
  border-color: #527bbd;
}

table.tableblock.frame-topbot {
  border-left-style: hidden;
  border-right-style: hidden;
}
table.tableblock.frame-sides {
  border-top-style: hidden;
  border-bottom-style: hidden;
}
table.tableblock.frame-none {
  border-style: hidden;
}

th.tableblock.halign-left, td.tableblock.halign-left {
  text-align: left;
}
th.tableblock.halign-center, td.tableblock.halign-center {
  text-align: center;
}
th.tableblock.halign-right, td.tableblock.halign-right {
  text-align: right;
}

th.tableblock.valign-top, td.tableblock.valign-top {
  vertical-align: top;
}
th.tableblock.valign-middle, td.tableblock.valign-middle {
  vertical-align: middle;
}
th.tableblock.valign-bottom, td.tableblock.valign-bottom {
  vertical-align: bottom;
}


/*
 * manpage specific
 *
 * */

body.manpage h1 {
  padding-top: 0.5em;
  padding-bottom: 0.5em;
  border-top: 2px solid silver;
  border-bottom: 2px solid silver;
}
body.manpage h2 {
  border-style: none;
}
body.manpage div.sectionbody {
  margin-left: 3em;
}

@media print {
  body.manpage div#toc { display: none; }
}
</style>
<script type="text/javascript">
/*<![CDATA[*/
var asciidoc = {  // Namespace.

/////////////////////////////////////////////////////////////////////
// Table Of Contents generator
/////////////////////////////////////////////////////////////////////

/* Author: Mihai Bazon, September 2002
 * http://students.infoiasi.ro/~mishoo
 *
 * Table Of Content generator
 * Version: 0.4
 *
 * Feel free to use this script under the terms of the GNU General Public
 * License, as long as you do not remove or alter this notice.
 */

 /* modified by Troy D. Hanson, September 2006. License: GPL */
 /* modified by Stuart Rackham, 2006, 2009. License: GPL */

// toclevels = 1..4.
toc: function (toclevels) {

  function getText(el) {
    var text = "";
    for (var i = el.firstChild; i != null; i = i.nextSibling) {
      if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
        text += i.data;
      else if (i.firstChild != null)
        text += getText(i);
    }
    return text;
  }

  function TocEntry(el, text, toclevel) {
    this.element = el;
    this.text = text;
    this.toclevel = toclevel;
  }

  function tocEntries(el, toclevels) {
    var result = new Array;
    var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
    // Function that scans the DOM tree for header elements (the DOM2
    // nodeIterator API would be a better technique but not supported by all
    // browsers).
    var iterate = function (el) {
      for (var i = el.firstChild; i != null; i = i.nextSibling) {
        if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
          var mo = re.exec(i.tagName);
          if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
            result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
          }
          iterate(i);
        }
      }
    }
    iterate(el);
    return result;
  }

  var toc = document.getElementById("toc");
  if (!toc) {
    return;
  }

  // Delete existing TOC entries in case we're reloading the TOC.
  var tocEntriesToRemove = [];
  var i;
  for (i = 0; i < toc.childNodes.length; i++) {
    var entry = toc.childNodes[i];
    if (entry.nodeName == 'div'
     && entry.getAttribute("class")
     && entry.getAttribute("class").match(/^toclevel/))
      tocEntriesToRemove.push(entry);
  }
  for (i = 0; i < tocEntriesToRemove.length; i++) {
    toc.removeChild(tocEntriesToRemove[i]);
  }

  // Rebuild TOC entries.
  var entries = tocEntries(document.getElementById("content"), toclevels);
  for (var i = 0; i < entries.length; ++i) {
    var entry = entries[i];
    if (entry.element.id == "")
      entry.element.id = "_toc_" + i;
    var a = document.createElement("a");
    a.href = "#" + entry.element.id;
    a.appendChild(document.createTextNode(entry.text));
    var div = document.createElement("div");
    div.appendChild(a);
    div.className = "toclevel" + entry.toclevel;
    toc.appendChild(div);
  }
  if (entries.length == 0)
    toc.parentNode.removeChild(toc);
},


/////////////////////////////////////////////////////////////////////
// Footnotes generator
/////////////////////////////////////////////////////////////////////

/* Based on footnote generation code from:
 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
 */

footnotes: function () {
  // Delete existing footnote entries in case we're reloading the footnodes.
  var i;
  var noteholder = document.getElementById("footnotes");
  if (!noteholder) {
    return;
  }
  var entriesToRemove = [];
  for (i = 0; i < noteholder.childNodes.length; i++) {
    var entry = noteholder.childNodes[i];
    if (entry.nodeName == 'div' && entry.getAttribute("class") == "footnote")
      entriesToRemove.push(entry);
  }
  for (i = 0; i < entriesToRemove.length; i++) {
    noteholder.removeChild(entriesToRemove[i]);
  }

  // Rebuild footnote entries.
  var cont = document.getElementById("content");
  var spans = cont.getElementsByTagName("span");
  var refs = {};
  var n = 0;
  for (i=0; i<spans.length; i++) {
    if (spans[i].className == "footnote") {
      n++;
      var note = spans[i].getAttribute("data-note");
      if (!note) {
        // Use [\s\S] in place of . so multi-line matches work.
        // Because JavaScript has no s (dotall) regex flag.
        note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
        spans[i].innerHTML =
          "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
          "' title='View footnote' class='footnote'>" + n + "</a>]";
        spans[i].setAttribute("data-note", note);
      }
      noteholder.innerHTML +=
        "<div class='footnote' id='_footnote_" + n + "'>" +
        "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
        n + "</a>. " + note + "</div>";
      var id =spans[i].getAttribute("id");
      if (id != null) refs["#"+id] = n;
    }
  }
  if (n == 0)
    noteholder.parentNode.removeChild(noteholder);
  else {
    // Process footnoterefs.
    for (i=0; i<spans.length; i++) {
      if (spans[i].className == "footnoteref") {
        var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
        href = href.match(/#.*/)[0];  // Because IE return full URL.
        n = refs[href];
        spans[i].innerHTML =
          "[<a href='#_footnote_" + n +
          "' title='View footnote' class='footnote'>" + n + "</a>]";
      }
    }
  }
},

install: function(toclevels) {
  var timerId;

  function reinstall() {
    asciidoc.footnotes();
    if (toclevels) {
      asciidoc.toc(toclevels);
    }
  }

  function reinstallAndRemoveTimer() {
    clearInterval(timerId);
    reinstall();
  }

  timerId = setInterval(reinstall, 500);
  if (document.addEventListener)
    document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
  else
    window.onload = reinstallAndRemoveTimer;
}

}
asciidoc.install(2);
/*]]>*/
</script>
</head>
<body class="article">
<div id="header">
<h1>Avro C</h1>
<div id="toc">
  <div id="toctitle">Table of Contents</div>
  <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>The current version of Avro is <tt>1.7.2</tt>.  The current version of <tt>libavro</tt> is <tt>22:0:0</tt>.
This document was created <tt>2012-09-17</tt>.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_introduction_to_avro">1. Introduction to Avro</h2>
<div class="sectionbody">
<div class="paragraph"><p>Avro is a data serialization system.</p></div>
<div class="paragraph"><p>Avro provides:</p></div>
<div class="ulist"><ul>
<li>
<p>
Rich data structures.
</p>
</li>
<li>
<p>
A compact, fast, binary data format.
</p>
</li>
<li>
<p>
A container file, to store persistent data.
</p>
</li>
<li>
<p>
Remote procedure call (RPC).
</p>
</li>
</ul></div>
<div class="paragraph"><p>This document will focus on the C implementation of Avro.  To learn more about
Avro in general, <a href="http://hadoop.apache.org/avro/">visit the Avro website</a>.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_introduction_to_avro_c">2. Introduction to Avro C</h2>
<div class="sectionbody">
<div class="literalblock">
<div class="content">
<pre><tt>    ___                      ______
   /   |_   ___________     / ____/
  / /| | | / / ___/ __ \   / /
 / ___ | |/ / /  / /_/ /  / /___
/_/  |_|___/_/   \____/   \____/</tt></pre>
</div></div>
<div class="quoteblock">
<div class="content">
<div class="paragraph"><p>A C program is like a fast dance on a newly waxed dance floor by people carrying razors.</p></div>
</div>
<div class="attribution">
<em>(walra%moacs11 @ nl.net) 94/03/18</em><br />
&#8212; Waldi Ravens
</div></div>
<div class="paragraph"><p>The C implementation has been tested on <tt>MacOSX</tt> and <tt>Linux</tt> but, over
time, the number of support OSes should grow.  Please let us know if
you&#8217;re using <tt>Avro C</tt> on other systems. There are no dependencies on
external libraries.  We embedded <a href="http://www.digip.org/jansson/">Jansson</a> into
<tt>Avro C</tt> for parsing JSON into schema structures.</p></div>
<div class="paragraph"><p>The C implementation supports:</p></div>
<div class="ulist"><ul>
<li>
<p>
binary encoding/decoding of all primitive and complex data types
</p>
</li>
<li>
<p>
storage to an Avro Object Container File
</p>
</li>
<li>
<p>
schema resolution, promotion and projection
</p>
</li>
<li>
<p>
validating and non-validating mode for writing Avro data
</p>
</li>
</ul></div>
<div class="paragraph"><p>The C implementation is lacking:</p></div>
<div class="ulist"><ul>
<li>
<p>
RPC
</p>
</li>
</ul></div>
<div class="paragraph"><p>To learn about the API, take a look at the examples and reference files
later in this document.</p></div>
<div class="paragraph"><p>We&#8217;re always looking for contributions so, if you&#8217;re a C hacker, please
feel free to <a href="http://hadoop.apache.org/avro/">submit patches to the
project</a>.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_error_reporting">3. Error reporting</h2>
<div class="sectionbody">
<div class="paragraph"><p>Most functions in the Avro C library return a single <tt>int</tt> status code.
Following the POSIX <em>errno.h</em> convention, a status code of 0 indicates
success.  Non-zero codes indiciate an error condition.  Some functions
return a pointer value instead of an <tt>int</tt> status code; for these
functions, a <tt>NULL</tt> pointer indicates an error.</p></div>
<div class="paragraph"><p>You can retrieve
a string description of the most recent error using the <tt>avro_strerror</tt>
function:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #008080">avro_schema_t</span>  schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_string</span></span><span style="color: #990000">();</span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>schema <span style="color: #990000">==</span> NULL<span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
    <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Error was %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_strerror</span></span><span style="color: #990000">());</span>
<span style="color: #FF0000">}</span></tt></pre></div></div>
</div>
</div>
<div class="sect1">
<h2 id="_avro_values">4. Avro values</h2>
<div class="sectionbody">
<div class="paragraph"><p>Starting with version 1.6.0, the Avro C library has a new API for
handling Avro data.  To help distinguish between the two APIs, we refer
to the old one as the <em>legacy</em> or <em>datum</em> API, and the new one as the
<em>value</em> API.  (These names come from the names of the C types used to
represent Avro data in the corresponding API — <tt>avro_datum_t</tt> and
<tt>avro_value_t</tt>.)  The legacy API is still present, but it&#8217;s deprecated —
you shouldn&#8217;t use the <tt>avro_datum_t</tt> type or the <tt>avro_datum_*</tt>
functions in new code.</p></div>
<div class="paragraph"><p>One main benefit of the new value API is that you can treat any existing
C type as an Avro value; you just have to provide a custom
implementation of the value interface.  In addition, we provide a
<em>generic</em> value implementation; “generic”, in this sense, meaning that
this single implementation works for instances of any Avro schema type.
Finally, we also provide a wrapper implementation for the deprecated
<tt>avro_datum_t</tt> type, which lets you gradually transition to the new
value API.</p></div>
<div class="sect2">
<h3 id="_avro_value_interface">4.1. Avro value interface</h3>
<div class="paragraph"><p>You interact with Avro values using the <em>value interface</em>, which defines
methods for setting and retrieving the contents of an Avro value.  An
individual value is represented by an instance of the <tt>avro_value_t</tt>
type.</p></div>
<div class="paragraph"><p>This section provides an overview of the methods that you can call on an
<tt>avro_value_t</tt> instance.  There are quite a few methods in the value
interface, but not all of them make sense for all Avro schema types.
For instance, you won&#8217;t be able to call <tt>avro_value_set_boolean</tt> on an
Avro array value.  If you try to call an inappropriate method, we&#8217;ll
return an <tt>EINVAL</tt> error code.</p></div>
<div class="paragraph"><p>Note that the functions in this section apply to <em>all</em> Avro values,
regardless of which value implementation is used under the covers.  This
section doesn&#8217;t describe how to <em>create</em> value instances, since those
constructors will be specific to a particular value implementation.</p></div>
<div class="sect3">
<h4 id="_common_methods">4.1.1. Common methods</h4>
<div class="paragraph"><p>There are a handful of methods that can be used with any value,
regardless of which Avro schema it&#8217;s an instance of:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;stdint.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro.h&gt;</span>

<span style="color: #008080">avro_type_t</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_type</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">);</span>
<span style="color: #008080">avro_schema_t</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_schema</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">);</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_equal</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>v1<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>v2<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_equal_fast</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>v1<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>v2<span style="color: #990000">);</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_copy</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>dest<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>src<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_copy_fast</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>dest<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>src<span style="color: #990000">);</span>

<span style="color: #008080">uint32_t</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_hash</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">);</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_reset</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>The <tt>get_type</tt> and <tt>get_schema</tt> methods can be used to get information
about what kind of Avro value a given <tt>avro_value_t</tt> instance
represents.  (For <tt>get_schema</tt>, you borrow the value&#8217;s reference to the
schema; if you need to save it and ensure that it outlives the value,
you need to call <tt>avro_schema_incref</tt> on it.)</p></div>
<div class="paragraph"><p>The <tt>equal</tt> and <tt>equal_fast</tt> methods compare two values for equality.
The two values do <em>not</em> have to have the same value implementations, but
they <em>do</em> have to be instances of the same schema.  (Not <em>equivalent</em>
schemas; the <em>same</em> schema.)  The <tt>equal</tt> method checks that the schemas
match; the <tt>equal_fast</tt> method assumes that they do.</p></div>
<div class="paragraph"><p>The <tt>copy</tt> and <tt>copy_fast</tt> methods copy the contents of one Avro value
into another.  (Where possible, this is done without copying the actual
content of a <tt>bytes</tt>, <tt>string</tt>, or <tt>fixed</tt> value, using the
<tt>avro_wrapped_buffer_t</tt> functions described in the next section.)  Like
<tt>equal</tt>, the two values must have the same schema; <tt>copy</tt> checks this,
while <tt>copy_fast</tt> assumes it.</p></div>
<div class="paragraph"><p>The <tt>hash</tt> method returns a hash value for the given Avro value.  This
can be used to construct hash tables that use Avro values as keys.  The
function works correctly even with maps; it produces a hash that doesn&#8217;t
depend on the ordering of the elements of the map.  Hash values are only
meaningful for comparing values of exactly the same schema.  Hash values
are <em>not</em> guaranteed to be consistent across different platforms, or
different versions of the Avro library.  That means that it&#8217;s really
only safe to use these hash values internally within the context of a
single execution of a single application.</p></div>
<div class="paragraph"><p>The <tt>reset</tt> method “clears out” an +avro_value_t instance, making sure
that it&#8217;s ready to accept the contents of a new value.  For scalars,
this is usually a no-op, since the new value will just overwrite the old
one.  For arrays and maps, this removes any existing elements from the
container, so that we can append the elements of the new value.  For
records and unions, this just recursively resets the fields or current
branch.</p></div>
</div>
<div class="sect3">
<h4 id="_scalar_values">4.1.2. Scalar values</h4>
<div class="paragraph"><p>The simplest case is handling instances of the scalar Avro schema types.
In Avro, the scalars are all of the primitive schema types, as well as
<tt>enum</tt> and <tt>fixed</tt> — i.e., anything that can&#8217;t contain another Avro
value.  Note that we use standard C99 types to represent the primitive
contents of an Avro scalar.</p></div>
<div class="paragraph"><p>To retrieve the contents of an Avro scalar, you can use one of the
<em>getter</em> methods:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;stdint.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;stdlib.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro.h&gt;</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_boolean</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #009900">int</span> <span style="color: #990000">*</span>dest<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_bytes</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span>
                         <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">void</span> <span style="color: #990000">**</span>dest<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> <span style="color: #990000">*</span>size<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_double</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #009900">double</span> <span style="color: #990000">*</span>dest<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_float</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #009900">float</span> <span style="color: #990000">*</span>dest<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_int</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #008080">int32_t</span> <span style="color: #990000">*</span>dest<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_long</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #008080">int64_t</span> <span style="color: #990000">*</span>dest<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_null</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_string</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span>
                          <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">**</span>dest<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> <span style="color: #990000">*</span>size<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_enum</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #009900">int</span> <span style="color: #990000">*</span>dest<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_fixed</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span>
                         <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">void</span> <span style="color: #990000">**</span>dest<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> <span style="color: #990000">*</span>size<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>For the most part, these should be self-explanatory.  For <tt>bytes</tt>,
<tt>string</tt>, and <tt>fixed</tt> values, the pointer to the underlying content is
<tt>const</tt> — you aren&#8217;t allowed to modify the contents directly.  We
guarantee that the content of a <tt>string</tt> will be NUL-terminated, so you
can use it as a C string as you&#8217;d expect.  The <tt>size</tt> returned for a
<tt>string</tt> object will include the NUL terminator; it will be one more
than you&#8217;d get from calling <tt>strlen</tt> on the content.</p></div>
<div class="paragraph"><p>Also, for <tt>bytes</tt>, <tt>string</tt>, and <tt>fixed</tt>, the <tt>dest</tt> and <tt>size</tt>
parameters are optional; if you only want to determine the length of a
<tt>bytes</tt> value, you can use:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #008080">avro_value_t</span>  <span style="color: #990000">*</span>value <span style="color: #990000">=</span> <span style="font-style: italic"><span style="color: #9A1900">/* from somewhere */</span></span><span style="color: #990000">;</span>
<span style="color: #008080">size_t</span>  size<span style="color: #990000">;</span>
<span style="font-weight: bold"><span style="color: #000000">avro_value_get_bytes</span></span><span style="color: #990000">(</span>value<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>size<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>To set the contents of an Avro scalar, you can use one of the <em>setter</em>
methods:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;stdint.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;stdlib.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro.h&gt;</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_set_boolean</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #009900">int</span> src<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_set_bytes</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span>
                         <span style="color: #009900">void</span> <span style="color: #990000">*</span>buf<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> size<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_set_double</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #009900">double</span> src<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_set_float</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #009900">float</span> src<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_set_int</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #008080">int32_t</span> src<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_set_long</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #008080">int64_t</span> src<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_set_null</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_set_string</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">*</span>src<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_set_string_len</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span>
                              <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">*</span>src<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> size<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_set_enum</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #009900">int</span> src<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_set_fixed</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span>
                         <span style="color: #009900">void</span> <span style="color: #990000">*</span>buf<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> size<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>These are also straightforward.  For <tt>bytes</tt>, <tt>string</tt>, and <tt>fixed</tt>
values, the <tt>set</tt> methods will make a copy of the underlying data.  For
<tt>string</tt> values, the content must be NUL-terminated.  You can use
<tt>set_string_len</tt> if you already know the length of the string content;
the length you pass in should include the NUL terminator.  If you call
<tt>set_string</tt>, then we&#8217;ll use <tt>strlen</tt> to calculate the length.</p></div>
<div class="paragraph"><p>For <tt>fixed</tt> values, the <tt>size</tt> must match what&#8217;s expected by the value&#8217;s
underlying <tt>fixed</tt> schema; if the sizes don&#8217;t match, you&#8217;ll get an error
code.</p></div>
<div class="paragraph"><p>If you don&#8217;t want to copy the contents of a <tt>bytes</tt>, <tt>string</tt>, or
<tt>fixed</tt> value, you can use the <em>giver</em> and <em>grabber</em> functions:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;stdint.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;stdlib.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro.h&gt;</span>

<span style="font-weight: bold"><span style="color: #0000FF">typedef</span></span> <span style="color: #009900">void</span>
<span style="color: #990000">(*</span>avro_buf_free_t<span style="color: #990000">)(</span><span style="color: #009900">void</span> <span style="color: #990000">*</span>ptr<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> sz<span style="color: #990000">,</span> <span style="color: #009900">void</span> <span style="color: #990000">*</span>user_data<span style="color: #990000">);</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_give_bytes</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>src<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_give_string_len</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>src<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_give_fixed</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>src<span style="color: #990000">);</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_grab_bytes</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>dest<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_grab_string</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>dest<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_grab_fixed</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>value<span style="color: #990000">,</span> <span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>dest<span style="color: #990000">);</span>

<span style="font-weight: bold"><span style="color: #0000FF">typedef</span></span> <span style="font-weight: bold"><span style="color: #0000FF">struct</span></span> <span style="color: #008080">avro_wrapped_buffer</span> <span style="color: #FF0000">{</span>
    <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">void</span>  <span style="color: #990000">*</span>buf<span style="color: #990000">;</span>
    <span style="color: #008080">size_t</span>  size<span style="color: #990000">;</span>
    <span style="color: #009900">void</span> <span style="color: #990000">(*</span>free<span style="color: #990000">)(</span><span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>self<span style="color: #990000">);</span>
    <span style="color: #009900">int</span> <span style="color: #990000">(*</span>copy<span style="color: #990000">)(</span><span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>dest<span style="color: #990000">,</span>
                <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>src<span style="color: #990000">,</span>
                <span style="color: #008080">size_t</span> offset<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> length<span style="color: #990000">);</span>
    <span style="color: #009900">int</span> <span style="color: #990000">(*</span>slice<span style="color: #990000">)(</span><span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>self<span style="color: #990000">,</span>
                 <span style="color: #008080">size_t</span> offset<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> length<span style="color: #990000">);</span>
<span style="color: #FF0000">}</span> avro_wrapped_buffer_t<span style="color: #990000">;</span>

<span style="color: #009900">void</span>
<span style="font-weight: bold"><span style="color: #000000">avro_wrapped_buffer_free</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>buf<span style="color: #990000">);</span>

<span style="color: #009900">int</span>
<span style="font-weight: bold"><span style="color: #000000">avro_wrapped_buffer_copy</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>dest<span style="color: #990000">,</span>
                         <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>src<span style="color: #990000">,</span>
                         <span style="color: #008080">size_t</span> offset<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> length<span style="color: #990000">);</span>

<span style="color: #009900">int</span>
<span style="font-weight: bold"><span style="color: #000000">avro_wrapped_buffer_slice</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_wrapped_buffer_t</span> <span style="color: #990000">*</span>self<span style="color: #990000">,</span>
                          <span style="color: #008080">size_t</span> offset<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> length<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>The <tt>give</tt> functions give control of an existing buffer to the value.
(You should <strong>not</strong> try to free the <tt>src</tt> wrapped buffer after calling
this method.)  The <tt>grab</tt> function fills in a wrapped buffer with a
pointer to the contents of an Avro value.  (You <strong>should</strong> free the <tt>dest</tt>
wrapped buffer when you&#8217;re done with it.)</p></div>
<div class="paragraph"><p>The <tt>avro_wrapped_buffer_t</tt> struct encapsulates the location and size of
the existing buffer.  It also includes several methods.  The <tt>free</tt>
method will be called when the content of the buffer is no longer
needed.  The <tt>slice</tt> method will be called when the wrapped buffer needs
to be updated to point at a subset of what it pointed at before.  (This
doesn&#8217;t create a new wrapped buffer; it updates an existing one.)  The
<tt>copy</tt> method will be called if the content needs to be copied.  Note
that if you&#8217;re wrapping a buffer with nice reference counting features,
you don&#8217;t need to perform an actual copy; you just need to ensure that
the <tt>free</tt> function can be called on both the original and the copy, and
not have things blow up.</p></div>
<div class="paragraph"><p>The “generic” value implementation takes advantage of this feature; if
you pass in a wrapped buffer with a <tt>give</tt> method, and then retrieve it
later with a <tt>grab</tt> method, then we&#8217;ll use the wrapped buffer&#8217;s <tt>copy</tt>
method to fill in the <tt>dest</tt> parameter.  If your wrapped buffer
implements a <tt>slice</tt> method that updates reference counts instead of
actually copying, then you&#8217;ve got nice zero-copy access to the contents
of an Avro value.</p></div>
</div>
<div class="sect3">
<h4 id="_compound_values">4.1.3. Compound values</h4>
<div class="paragraph"><p>The following sections describe the getter and setter methods for
handling compound Avro values.  All of the compound values are
responsible for the storage of their children; this means that there
isn&#8217;t a method, for instance, that lets you add an existing
<tt>avro_value_t</tt> to an array.  Instead, there&#8217;s a method that creates a
new, empty <tt>avro_value_t</tt> of the appropriate type, adds it to the array,
and returns it for you to fill in as needed.</p></div>
<div class="paragraph"><p>You also shouldn&#8217;t try to free the child elements that are created this
way; the container value is responsible for their life cycle.  The child
element is guaranteed to be valid for as long as the container value
is.  You&#8217;ll usually define an <tt>avro_value_t</tt> in the stack, and let it
fall out of scope when you&#8217;re done with it:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #008080">avro_value_t</span>  <span style="color: #990000">*</span>array <span style="color: #990000">=</span> <span style="font-style: italic"><span style="color: #9A1900">/* from somewhere else */</span></span><span style="color: #990000">;</span>

<span style="color: #FF0000">{</span>
    <span style="color: #008080">avro_value_t</span>  child<span style="color: #990000">;</span>
    <span style="font-weight: bold"><span style="color: #000000">avro_value_get_by_index</span></span><span style="color: #990000">(</span>array<span style="color: #990000">,</span> <span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>child<span style="color: #990000">,</span> NULL<span style="color: #990000">);</span>
    <span style="font-style: italic"><span style="color: #9A1900">/* do something interesting with the array element */</span></span>
<span style="color: #FF0000">}</span></tt></pre></div></div>
</div>
<div class="sect3">
<h4 id="_arrays">4.1.4. Arrays</h4>
<div class="paragraph"><p>There are three methods that can be used with array values:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;stdlib.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro.h&gt;</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_size</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>array<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> <span style="color: #990000">*</span>size<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_by_index</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>array<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> index<span style="color: #990000">,</span>
                            <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>element<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">**</span>unused<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_append</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>array<span style="color: #990000">,</span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>element<span style="color: #990000">,</span>
                      <span style="color: #008080">size_t</span> <span style="color: #990000">*</span>new_index<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>The <tt>get_size</tt> method returns the number of elements currently in the
array.  The <tt>get_by_index</tt> method fills in <tt>element</tt> to point at the
array element with the given index.  (You should use <tt>NULL</tt> for the
<tt>unused</tt> parameter; it&#8217;s ignored for array values.)</p></div>
<div class="paragraph"><p>The <tt>append</tt> method creates a new value, appends it to the array, and
returns it in <tt>element</tt>.  If <tt>new_index</tt> is given, then it will be
filled in with the index of the new element.</p></div>
</div>
<div class="sect3">
<h4 id="_maps">4.1.5. Maps</h4>
<div class="paragraph"><p>There are four methods that can be used with map values:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;stdlib.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro.h&gt;</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_size</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>map<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> <span style="color: #990000">*</span>size<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_by_name</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>map<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">*</span>key<span style="color: #990000">,</span>
                           <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>element<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> <span style="color: #990000">*</span>index<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_by_index</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>map<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> index<span style="color: #990000">,</span>
                            <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>element<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">**</span>key<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_add</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>map<span style="color: #990000">,</span>
                   <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">*</span>key<span style="color: #990000">,</span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>element<span style="color: #990000">,</span>
                   <span style="color: #008080">size_t</span> <span style="color: #990000">*</span>index<span style="color: #990000">,</span> <span style="color: #009900">int</span> <span style="color: #990000">*</span>is_new<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>The <tt>get_size</tt> method returns the number of elements currently in the
map.  Map elements can be retrieved either by their key (<tt>get_by_name</tt>)
or by their numeric index (<tt>get_by_index</tt>).  (Numeric indices in a map
are based on the order that the elements were added to the map.)  In
either case, the method takes in an optional output parameter that let
you retrieve the index associated with a key, and vice versa.</p></div>
<div class="paragraph"><p>The <tt>add</tt> method will add a new value to the map, if the given key isn&#8217;t
already present.  If the key is present, then the existing value with be
returned.  The <tt>index</tt> parameter, if given, will be filled in the
element&#8217;s index.  The <tt>is_new</tt> parameter, if given, can be used to
determine whether the mapped value is new or not.</p></div>
</div>
<div class="sect3">
<h4 id="_records">4.1.6. Records</h4>
<div class="paragraph"><p>There are three methods that can be used with record values:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;stdlib.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro.h&gt;</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_size</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>record<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> <span style="color: #990000">*</span>size<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_by_index</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>record<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> index<span style="color: #990000">,</span>
                            <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>element<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">**</span>field_name<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_by_name</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>record<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">*</span>field_name<span style="color: #990000">,</span>
                           <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>element<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> <span style="color: #990000">*</span>index<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>The <tt>get_size</tt> method returns the number of fields in the record.  (You
can also get this by querying the value&#8217;s schema, but for some
implementations, this method can be faster.)</p></div>
<div class="paragraph"><p>The <tt>get_by_index</tt> and <tt>get_by_name</tt> functions can be used to retrieve
one of the fields in the record, either by its ordinal position within
the record, or by the name of the underlying field.  Like with maps, the
methods take in an additional parameter that let you retrieve the index
associated with a field name, and vice versa.</p></div>
<div class="paragraph"><p>When possible, it&#8217;s recommended that you access record fields by their
numeric index, rather than by their field name.  For most
implementations, this will be more efficient.</p></div>
</div>
<div class="sect3">
<h4 id="_unions">4.1.7. Unions</h4>
<div class="paragraph"><p>There are three methods that can be used with union values:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro.h&gt;</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_discriminant</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>union_val<span style="color: #990000">,</span> <span style="color: #009900">int</span> <span style="color: #990000">*</span>disc<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_get_current_branch</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>union_val<span style="color: #990000">,</span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>branch<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_set_branch</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>union_val<span style="color: #990000">,</span>
                          <span style="color: #009900">int</span> discriminant<span style="color: #990000">,</span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>branch<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>The <tt>get_discriminant</tt> and <tt>get_current_branch</tt> methods return the
current state of the union value, without modifying which branch is
currently selected.  The <tt>set_branch</tt> method can be used to choose the
active branch, filling in the <tt>branch</tt> value to point at the branch&#8217;s
value instance.  (Most implementations will be smart enough to detect
when the desired branch is already selected, so you should always call
this method unless you can <em>guarantee</em> that the right branch is already
current.)</p></div>
</div>
</div>
<div class="sect2">
<h3 id="_creating_value_instances">4.2. Creating value instances</h3>
<div class="paragraph"><p>Okay, so we&#8217;ve described how to interact with a value that you already
have a pointer to, but how do you create one in the first place?  Each
implementation of the value interface must provide its own functions for
creating <tt>avro_value_t</tt> instances for that class.  The 10,000-foot view
is to:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Get an <em>implementation struct</em> for the value implementation that you
   want to use.  (This is represented by an <tt>avro_value_iface_t</tt>
   pointer.)
</p>
</li>
<li>
<p>
Use the implementation&#8217;s constructor function to allocate instances
   of that value implementation.
</p>
</li>
<li>
<p>
Do whatever you need to the value (using the <tt>avro_value_t</tt> methods
   described in the previous section).
</p>
</li>
<li>
<p>
Free the value instance, if necessary, using the implementation&#8217;s
   destructor function.
</p>
</li>
<li>
<p>
Free the implementation struct when you&#8217;re done creating value
   instances.
</p>
</li>
</ol></div>
<div class="paragraph"><p>These steps use the following functions:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro.h&gt;</span>

<span style="color: #008080">avro_value_iface_t</span> <span style="color: #990000">*</span><span style="font-weight: bold"><span style="color: #000000">avro_value_iface_incref</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_iface_t</span> <span style="color: #990000">*</span>iface<span style="color: #990000">);</span>
<span style="color: #009900">void</span> <span style="font-weight: bold"><span style="color: #000000">avro_value_iface_decref</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_iface_t</span> <span style="color: #990000">*</span>iface<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>Note that for most value implementations, it&#8217;s fine to reuse a single
<tt>avro_value_t</tt> instance for multiple values, using the
<tt>avro_value_reset</tt> function before filling in the instance for each
value.  (This helps reduce the number of <tt>malloc</tt> and <tt>free</tt> calls that
your application will make.)</p></div>
<div class="paragraph"><p>We provide a “generic” value implementation that will work (efficiently)
for any Avro schema.</p></div>
<div class="paragraph"><p>For most applications, you won&#8217;t need to write your own value
implementation; the Avro C library provides an efficient “generic”
implementation, which supports the full range of Avro schema types.
There&#8217;s a good chance that you just want to use this implementation,
rather than rolling your own.  (The primary reason for rolling your own
would be if you want to access the elements of a compound value using C
syntax — for instance, translating an Avro record into a C struct.) You
can use the following functions to create and work with a generic value
implementation for a particular schema:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro.h&gt;</span>

<span style="color: #008080">avro_value_iface_t</span> <span style="color: #990000">*</span><span style="font-weight: bold"><span style="color: #000000">avro_generic_class_from_schema</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_schema_t</span> schema<span style="color: #990000">);</span>
<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_generic_value_new</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #008080">avro_value_iface_t</span> <span style="color: #990000">*</span>iface<span style="color: #990000">,</span> <span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>dest<span style="color: #990000">);</span>
<span style="color: #009900">void</span> <span style="font-weight: bold"><span style="color: #000000">avro_generic_value_free</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_value_t</span> <span style="color: #990000">*</span>self<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>Combining all of this together, you might have the following snippet of
code:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #008080">avro_schema_t</span>  schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_long</span></span><span style="color: #990000">();</span>
<span style="color: #008080">avro_value_iface_t</span>  <span style="color: #990000">*</span>iface <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_generic_class_from_schema</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>

<span style="color: #008080">avro_value_t</span>  val<span style="color: #990000">;</span>
<span style="font-weight: bold"><span style="color: #000000">avro_generic_value_new</span></span><span style="color: #990000">(</span>iface<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>val<span style="color: #990000">);</span>

<span style="font-style: italic"><span style="color: #9A1900">/* Generate Avro longs from 0-499 */</span></span>
<span style="color: #009900">int</span>  i<span style="color: #990000">;</span>
<span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #990000">(</span>i <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span> i <span style="color: #990000">&lt;</span> <span style="color: #993399">500</span><span style="color: #990000">;</span> i<span style="color: #990000">++)</span> <span style="color: #FF0000">{</span>
    <span style="font-weight: bold"><span style="color: #000000">avro_value_reset</span></span><span style="color: #990000">(&amp;</span>val<span style="color: #990000">);</span>
    <span style="font-weight: bold"><span style="color: #000000">avro_value_set_long</span></span><span style="color: #990000">(&amp;</span>val<span style="color: #990000">,</span> i<span style="color: #990000">);</span>
    <span style="font-style: italic"><span style="color: #9A1900">/* do something with the value */</span></span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #000000">avro_generic_value_free</span></span><span style="color: #990000">(&amp;</span>val<span style="color: #990000">);</span>
<span style="font-weight: bold"><span style="color: #000000">avro_value_iface_decref</span></span><span style="color: #990000">(</span>iface<span style="color: #990000">);</span>
<span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span></tt></pre></div></div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_reference_counting">5. Reference Counting</h2>
<div class="sectionbody">
<div class="paragraph"><p><tt>Avro C</tt> does reference counting for all schema and data objects.
When the number of references drops to zero, the memory is freed.</p></div>
<div class="paragraph"><p>For example, to create and free a string, you would use:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>avro_datum_t string = avro_string("This is my string");

...
avro_datum_decref(string);</tt></pre>
</div></div>
<div class="paragraph"><p>Things get a little more complicated when you consider more elaborate
schema and data structures.</p></div>
<div class="paragraph"><p>For example, let&#8217;s say that you create a record with a single
string field:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>avro_datum_t example = avro_record("Example");
avro_datum_t solo_field = avro_string("Example field value");

avro_record_set(example, "solo", solo_field);

...
avro_datum_decref(example);</tt></pre>
</div></div>
<div class="paragraph"><p>In this example, the <tt>solo_field</tt> datum would <strong>not</strong> be freed since it
has two references: the original reference and a reference inside
the <tt>Example</tt> record.  The <tt>avro_datum_decref(example)</tt> call drops
the number of reference to one.  If you are finished with the <tt>solo_field</tt>
schema, then you need to <tt>avro_schema_decref(solo_field)</tt> to
completely dereference the <tt>solo_field</tt> datum and free it.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_wrap_it_and_give_it">6. Wrap It and Give It</h2>
<div class="sectionbody">
<div class="paragraph"><p>You&#8217;ll notice that some datatypes can be "wrapped" and "given".  This
allows C programmers the freedom to decide who is responsible for
the memory.  Let&#8217;s take strings for example.</p></div>
<div class="paragraph"><p>To create a string datum, you have three different methods:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>avro_datum_t avro_string(const char *str);
avro_datum_t avro_wrapstring(const char *str);
avro_datum_t avro_givestring(const char *str);</tt></pre>
</div></div>
<div class="paragraph"><p>If you use, <tt>avro_string</tt> then <tt>Avro C</tt> will make a copy of your
string and free it when the datum is dereferenced.  In some cases,
especially when dealing with large amounts of data, you want
to avoid this memory copy.  That&#8217;s where <tt>avro_wrapstring</tt> and
<tt>avro_givestring</tt> can help.</p></div>
<div class="paragraph"><p>If you use, <tt>avro_wrapstring</tt> then <tt>Avro C</tt> will do no memory
management at all.  It will just save a pointer to your data and
it&#8217;s your responsibility to free the string.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<div class="title">Warning</div>
</td>
<td class="content">When using <tt>avro_wrapstring</tt>, do not free the string
before you dereference the string datum with <tt>avro_datum_decref()</tt>.</td>
</tr></table>
</div>
<div class="paragraph"><p>Lastly, if you use <tt>avro_givestring</tt> then <tt>Avro C</tt> will free the
string later when the datum is dereferenced.  In a sense, you
are "giving" responsibility for freeing the string to <tt>Avro C</tt>.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<div class="title">Warning</div>
</td>
<td class="content">
<div class="paragraph"><p>Don&#8217;t "give" <tt>Avro C</tt> a string that you haven&#8217;t allocated from the heap with e.g. <tt>malloc</tt> or <tt>strdup</tt>.</p></div>
<div class="paragraph"><p>For example, <strong>don&#8217;t</strong> do this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>avro_datum_t bad_idea = avro_givestring("This isn't allocated on the heap");</tt></pre>
</div></div>
</td>
</tr></table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_schema_validation">7. Schema Validation</h2>
<div class="sectionbody">
<div class="paragraph"><p>If you want to write a datum, you would use the following function</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">avro_write_data</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_writer_t</span> writer<span style="color: #990000">,</span>
                    <span style="color: #008080">avro_schema_t</span> writers_schema<span style="color: #990000">,</span> <span style="color: #008080">avro_datum_t</span> datum<span style="color: #990000">);</span></tt></pre></div></div>
<div class="paragraph"><p>If you pass in a <tt>writers_schema</tt>, then you <tt>datum</tt> will be validated <strong>before</strong>
it is sent to the <tt>writer</tt>.  This check ensures that your data has the
correct format.  If you are certain your datum is correct, you can pass
a <tt>NULL</tt> value for <tt>writers_schema</tt> and <tt>Avro C</tt> will not validate before
writing.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">Data written to an Avro File Object Container is always validated.</td>
</tr></table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_examples">8. Examples</h2>
<div class="sectionbody">
<div class="quoteblock">
<div class="content">
<div class="paragraph"><p>I&#8217;m not even supposed to be here today!</p></div>
</div>
<div class="attribution">
&#8212; Dante Hicks
</div></div>
<div class="paragraph"><p>Imagine you&#8217;re a free-lance hacker in Leonardo, New Jersey and you&#8217;ve
been approached by the owner of the local <strong>Quick Stop Convenience</strong> store.
He wants you to create a contact database case he needs to call employees
to work on their day off.</p></div>
<div class="paragraph"><p>You might build a simple contact system using Avro C like the following&#8230;</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-style: italic"><span style="color: #9A1900">/*</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * Licensed to the Apache Software Foundation (ASF) under one or more</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * contributor license agreements.  See the NOTICE file distributed with</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * this work for additional information regarding copyright ownership.</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * The ASF licenses this file to you under the Apache License, Version 2.0</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * (the "License"); you may not use this file except in compliance with</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * the License.  You may obtain a copy of the License at</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> *</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * </span></span><span style="text-decoration: underline"><span style="color: #0000FF">http://www.apache.org/licenses/LICENSE-2.0</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> *</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * Unless required by applicable law or agreed to in writing, software</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * distributed under the License is distributed on an "AS IS" BASIS,</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * implied.  See the License for the specific language governing</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * permissions and limitations under the License.</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> */</span></span>

<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;stdio.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;stdlib.h&gt;</span>

<span style="font-weight: bold"><span style="color: #000080">#ifdef</span></span> DEFLATE_CODEC
<span style="font-weight: bold"><span style="color: #000080">#define</span></span> QUICKSTOP_CODEC  <span style="color: #FF0000">"deflate"</span>
<span style="font-weight: bold"><span style="color: #000080">#else</span></span>
<span style="font-weight: bold"><span style="color: #000080">#define</span></span> QUICKSTOP_CODEC  <span style="color: #FF0000">"null"</span>
<span style="font-weight: bold"><span style="color: #000080">#endif</span></span>

<span style="color: #008080">avro_schema_t</span> person_schema<span style="color: #990000">;</span>
<span style="color: #008080">int64_t</span> id <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span>

<span style="font-style: italic"><span style="color: #9A1900">/* A simple schema for our tutorial */</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span>  PERSON_SCHEMA<span style="color: #990000">[]</span> <span style="color: #990000">=</span>
<span style="color: #FF0000">"{</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">type</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">:</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">record</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">,\</span>
<span style="color: #FF0000">  </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">name</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">:</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">Person</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">,\</span>
<span style="color: #FF0000">  </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">fields</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">:[\</span>
<span style="color: #FF0000">     {</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">name</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">ID</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">type</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">long</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">},\</span>
<span style="color: #FF0000">     {</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">name</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">First</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">type</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">string</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">},\</span>
<span style="color: #FF0000">     {</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">name</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">Last</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">type</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">string</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">},\</span>
<span style="color: #FF0000">     {</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">name</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">Phone</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">type</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">string</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">},\</span>
<span style="color: #FF0000">     {</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">name</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">Age</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">type</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">int</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">}]}"</span><span style="color: #990000">;</span>

<span style="font-style: italic"><span style="color: #9A1900">/* Parse schema into a schema data structure */</span></span>
<span style="color: #009900">void</span> <span style="font-weight: bold"><span style="color: #000000">init_schema</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_schema_from_json_literal</span></span><span style="color: #990000">(</span>PERSON_SCHEMA<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>person_schema<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unable to parse person schema</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>
<span style="color: #FF0000">}</span>

<span style="font-style: italic"><span style="color: #9A1900">/* Create a datum to match the person schema and save it */</span></span>
<span style="color: #009900">void</span>
<span style="font-weight: bold"><span style="color: #000000">add_person</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_file_writer_t</span> db<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">*</span>first<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">*</span>last<span style="color: #990000">,</span>
           <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">*</span>phone<span style="color: #990000">,</span> <span style="color: #008080">int32_t</span> age<span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #008080">avro_datum_t</span> person <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_record</span></span><span style="color: #990000">(</span>person_schema<span style="color: #990000">);</span>

        <span style="color: #008080">avro_datum_t</span> id_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_int64</span></span><span style="color: #990000">(++</span>id<span style="color: #990000">);</span>
        <span style="color: #008080">avro_datum_t</span> first_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_string</span></span><span style="color: #990000">(</span>first<span style="color: #990000">);</span>
        <span style="color: #008080">avro_datum_t</span> last_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_string</span></span><span style="color: #990000">(</span>last<span style="color: #990000">);</span>
        <span style="color: #008080">avro_datum_t</span> age_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_int32</span></span><span style="color: #990000">(</span>age<span style="color: #990000">);</span>
        <span style="color: #008080">avro_datum_t</span> phone_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_string</span></span><span style="color: #990000">(</span>phone<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_record_set</span></span><span style="color: #990000">(</span>person<span style="color: #990000">,</span> <span style="color: #FF0000">"ID"</span><span style="color: #990000">,</span> id_datum<span style="color: #990000">)</span>
            <span style="color: #990000">||</span> <span style="font-weight: bold"><span style="color: #000000">avro_record_set</span></span><span style="color: #990000">(</span>person<span style="color: #990000">,</span> <span style="color: #FF0000">"First"</span><span style="color: #990000">,</span> first_datum<span style="color: #990000">)</span>
            <span style="color: #990000">||</span> <span style="font-weight: bold"><span style="color: #000000">avro_record_set</span></span><span style="color: #990000">(</span>person<span style="color: #990000">,</span> <span style="color: #FF0000">"Last"</span><span style="color: #990000">,</span> last_datum<span style="color: #990000">)</span>
            <span style="color: #990000">||</span> <span style="font-weight: bold"><span style="color: #000000">avro_record_set</span></span><span style="color: #990000">(</span>person<span style="color: #990000">,</span> <span style="color: #FF0000">"Age"</span><span style="color: #990000">,</span> age_datum<span style="color: #990000">)</span>
            <span style="color: #990000">||</span> <span style="font-weight: bold"><span style="color: #000000">avro_record_set</span></span><span style="color: #990000">(</span>person<span style="color: #990000">,</span> <span style="color: #FF0000">"Phone"</span><span style="color: #990000">,</span> phone_datum<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unable to create Person datum structure</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_file_writer_append</span></span><span style="color: #990000">(</span>db<span style="color: #990000">,</span> person<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span>
                        <span style="color: #FF0000">"Unable to write Person datum to memory buffer</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">Message: %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_strerror</span></span><span style="color: #990000">());</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="font-style: italic"><span style="color: #9A1900">/* Decrement all our references to prevent memory from leaking */</span></span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>id_datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>first_datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>last_datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>age_datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>phone_datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>person<span style="color: #990000">);</span>

        <span style="font-style: italic"><span style="color: #9A1900">//fprintf(stdout, "Successfully added %s, %s id=%"PRId64"\n", last, first, id);</span></span>
<span style="color: #FF0000">}</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">print_person</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_file_reader_t</span> db<span style="color: #990000">,</span> <span style="color: #008080">avro_schema_t</span> reader_schema<span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #009900">int</span> rval<span style="color: #990000">;</span>
        <span style="color: #008080">avro_datum_t</span> person<span style="color: #990000">;</span>

        rval <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_file_reader_read</span></span><span style="color: #990000">(</span>db<span style="color: #990000">,</span> reader_schema<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>person<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>rval <span style="color: #990000">==</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="color: #008080">int64_t</span> i64<span style="color: #990000">;</span>
                <span style="color: #008080">int32_t</span> i32<span style="color: #990000">;</span>
                <span style="color: #009900">char</span> <span style="color: #990000">*</span>p<span style="color: #990000">;</span>
                <span style="color: #008080">avro_datum_t</span> id_datum<span style="color: #990000">,</span> first_datum<span style="color: #990000">,</span> last_datum<span style="color: #990000">,</span> phone_datum<span style="color: #990000">,</span>
                    age_datum<span style="color: #990000">;</span>

                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_record_get</span></span><span style="color: #990000">(</span>person<span style="color: #990000">,</span> <span style="color: #FF0000">"ID"</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>id_datum<span style="color: #990000">)</span> <span style="color: #990000">==</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #000000">avro_int64_get</span></span><span style="color: #990000">(</span>id_datum<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>i64<span style="color: #990000">);</span>
                        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stdout<span style="color: #990000">,</span> <span style="color: #FF0000">"%"</span>PRId64<span style="color: #FF0000">" | "</span><span style="color: #990000">,</span> i64<span style="color: #990000">);</span>
                <span style="color: #FF0000">}</span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_record_get</span></span><span style="color: #990000">(</span>person<span style="color: #990000">,</span> <span style="color: #FF0000">"First"</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>first_datum<span style="color: #990000">)</span> <span style="color: #990000">==</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #000000">avro_string_get</span></span><span style="color: #990000">(</span>first_datum<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>p<span style="color: #990000">);</span>
                        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stdout<span style="color: #990000">,</span> <span style="color: #FF0000">"%15s | "</span><span style="color: #990000">,</span> p<span style="color: #990000">);</span>
                <span style="color: #FF0000">}</span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_record_get</span></span><span style="color: #990000">(</span>person<span style="color: #990000">,</span> <span style="color: #FF0000">"Last"</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>last_datum<span style="color: #990000">)</span> <span style="color: #990000">==</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #000000">avro_string_get</span></span><span style="color: #990000">(</span>last_datum<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>p<span style="color: #990000">);</span>
                        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stdout<span style="color: #990000">,</span> <span style="color: #FF0000">"%15s | "</span><span style="color: #990000">,</span> p<span style="color: #990000">);</span>
                <span style="color: #FF0000">}</span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_record_get</span></span><span style="color: #990000">(</span>person<span style="color: #990000">,</span> <span style="color: #FF0000">"Phone"</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>phone_datum<span style="color: #990000">)</span> <span style="color: #990000">==</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #000000">avro_string_get</span></span><span style="color: #990000">(</span>phone_datum<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>p<span style="color: #990000">);</span>
                        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stdout<span style="color: #990000">,</span> <span style="color: #FF0000">"%15s | "</span><span style="color: #990000">,</span> p<span style="color: #990000">);</span>
                <span style="color: #FF0000">}</span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_record_get</span></span><span style="color: #990000">(</span>person<span style="color: #990000">,</span> <span style="color: #FF0000">"Age"</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>age_datum<span style="color: #990000">)</span> <span style="color: #990000">==</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #000000">avro_int32_get</span></span><span style="color: #990000">(</span>age_datum<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>i32<span style="color: #990000">);</span>
                        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stdout<span style="color: #990000">,</span> <span style="color: #FF0000">"%d"</span><span style="color: #990000">,</span> i32<span style="color: #990000">);</span>
                <span style="color: #FF0000">}</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stdout<span style="color: #990000">,</span> <span style="color: #FF0000">"</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>

                <span style="font-style: italic"><span style="color: #9A1900">/* We no longer need this memory */</span></span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>person<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> rval<span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">main</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #009900">int</span> rval<span style="color: #990000">;</span>
        <span style="color: #008080">avro_file_reader_t</span> dbreader<span style="color: #990000">;</span>
        <span style="color: #008080">avro_file_writer_t</span> db<span style="color: #990000">;</span>
        <span style="color: #008080">avro_schema_t</span> projection_schema<span style="color: #990000">,</span> first_name_schema<span style="color: #990000">,</span> phone_schema<span style="color: #990000">;</span>
        <span style="color: #008080">int64_t</span> i<span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">*</span>dbname <span style="color: #990000">=</span> <span style="color: #FF0000">"quickstop.db"</span><span style="color: #990000">;</span>
        <span style="color: #009900">char</span> number<span style="color: #990000">[</span><span style="color: #993399">15</span><span style="color: #990000">]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">{</span><span style="color: #993399">0</span><span style="color: #FF0000">}</span><span style="color: #990000">;</span>

        <span style="font-style: italic"><span style="color: #9A1900">/* Initialize the schema structure from JSON */</span></span>
        <span style="font-weight: bold"><span style="color: #000000">init_schema</span></span><span style="color: #990000">();</span>

        <span style="font-style: italic"><span style="color: #9A1900">/* Delete the database if it exists */</span></span>
        <span style="font-weight: bold"><span style="color: #000000">remove</span></span><span style="color: #990000">(</span>dbname<span style="color: #990000">);</span>
        <span style="font-style: italic"><span style="color: #9A1900">/* Create a new database */</span></span>
        rval <span style="color: #990000">=</span> avro_file_writer_create_with_codec
            <span style="color: #990000">(</span>dbname<span style="color: #990000">,</span> person_schema<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>db<span style="color: #990000">,</span> QUICKSTOP_CODEC<span style="color: #990000">,</span> <span style="color: #993399">0</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>rval<span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"There was an error creating %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span> dbname<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">" error message: %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_strerror</span></span><span style="color: #990000">());</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="font-style: italic"><span style="color: #9A1900">/* Add lots of people to the database */</span></span>
        <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #990000">(</span>i <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span> i <span style="color: #990000">&lt;</span> <span style="color: #993399">1000</span><span style="color: #990000">;</span> i<span style="color: #990000">++)</span>
        <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">sprintf</span></span><span style="color: #990000">(</span>number<span style="color: #990000">,</span> <span style="color: #FF0000">"(%d)"</span><span style="color: #990000">,</span> <span style="color: #990000">(</span><span style="color: #009900">int</span><span style="color: #990000">)</span>i<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">add_person</span></span><span style="color: #990000">(</span>db<span style="color: #990000">,</span> <span style="color: #FF0000">"Dante"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"Hicks"</span><span style="color: #990000">,</span> number<span style="color: #990000">,</span> <span style="color: #993399">32</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">add_person</span></span><span style="color: #990000">(</span>db<span style="color: #990000">,</span> <span style="color: #FF0000">"Randal"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"Graves"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"(555) 123-5678"</span><span style="color: #990000">,</span> <span style="color: #993399">30</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">add_person</span></span><span style="color: #990000">(</span>db<span style="color: #990000">,</span> <span style="color: #FF0000">"Veronica"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"Loughran"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"(555) 123-0987"</span><span style="color: #990000">,</span> <span style="color: #993399">28</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">add_person</span></span><span style="color: #990000">(</span>db<span style="color: #990000">,</span> <span style="color: #FF0000">"Caitlin"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"Bree"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"(555) 123-2323"</span><span style="color: #990000">,</span> <span style="color: #993399">27</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">add_person</span></span><span style="color: #990000">(</span>db<span style="color: #990000">,</span> <span style="color: #FF0000">"Bob"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"Silent"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"(555) 123-6422"</span><span style="color: #990000">,</span> <span style="color: #993399">29</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">add_person</span></span><span style="color: #990000">(</span>db<span style="color: #990000">,</span> <span style="color: #FF0000">"Jay"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"???"</span><span style="color: #990000">,</span> number<span style="color: #990000">,</span> <span style="color: #993399">26</span><span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="font-style: italic"><span style="color: #9A1900">/* Close the block and open a new one */</span></span>
        <span style="font-weight: bold"><span style="color: #000000">avro_file_writer_flush</span></span><span style="color: #990000">(</span>db<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">add_person</span></span><span style="color: #990000">(</span>db<span style="color: #990000">,</span> <span style="color: #FF0000">"Super"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"Man"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"123456"</span><span style="color: #990000">,</span> <span style="color: #993399">31</span><span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_file_writer_close</span></span><span style="color: #990000">(</span>db<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stdout<span style="color: #990000">,</span> <span style="color: #FF0000">"</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">Now let's read all the records back out</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>

        <span style="font-style: italic"><span style="color: #9A1900">/* Read all the records and print them */</span></span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_file_reader</span></span><span style="color: #990000">(</span>dbname<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>dbreader<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Error opening file: %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_strerror</span></span><span style="color: #990000">());</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>
        <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #990000">(</span>i <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span> i <span style="color: #990000">&lt;</span> id<span style="color: #990000">;</span> i<span style="color: #990000">++)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">print_person</span></span><span style="color: #990000">(</span>dbreader<span style="color: #990000">,</span> NULL<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Error printing person</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">Message: %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_strerror</span></span><span style="color: #990000">());</span>
                        <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
                <span style="color: #FF0000">}</span>
        <span style="color: #FF0000">}</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_file_reader_close</span></span><span style="color: #990000">(</span>dbreader<span style="color: #990000">);</span>

        <span style="font-style: italic"><span style="color: #9A1900">/* You can also use projection, to only decode only the data you are</span></span>
<span style="font-style: italic"><span style="color: #9A1900">           interested in.  This is particularly useful when you have</span></span>
<span style="font-style: italic"><span style="color: #9A1900">           huge data sets and you'll only interest in particular fields</span></span>
<span style="font-style: italic"><span style="color: #9A1900">           e.g. your contacts First name and phone number */</span></span>
        projection_schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_record</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"Person"</span><span style="color: #990000">,</span> NULL<span style="color: #990000">);</span>
        first_name_schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_string</span></span><span style="color: #990000">();</span>
        phone_schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_string</span></span><span style="color: #990000">();</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_record_field_append</span></span><span style="color: #990000">(</span>projection_schema<span style="color: #990000">,</span> <span style="color: #FF0000">"First"</span><span style="color: #990000">,</span>
                                        first_name_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_record_field_append</span></span><span style="color: #990000">(</span>projection_schema<span style="color: #990000">,</span> <span style="color: #FF0000">"Phone"</span><span style="color: #990000">,</span>
                                        phone_schema<span style="color: #990000">);</span>

        <span style="font-style: italic"><span style="color: #9A1900">/* Read only the record you're interested in */</span></span>
        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stdout<span style="color: #990000">,</span>
                <span style="color: #FF0000">"</span><span style="color: #CC33CC">\n\n</span><span style="color: #FF0000">Use projection to print only the First name and phone numbers</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_file_reader</span></span><span style="color: #990000">(</span>dbname<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>dbreader<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Error opening file: %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_strerror</span></span><span style="color: #990000">());</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>
        <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #990000">(</span>i <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span> i <span style="color: #990000">&lt;</span> id<span style="color: #990000">;</span> i<span style="color: #990000">++)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">print_person</span></span><span style="color: #990000">(</span>dbreader<span style="color: #990000">,</span> projection_schema<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Error printing person: %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span>
                                <span style="font-weight: bold"><span style="color: #000000">avro_strerror</span></span><span style="color: #990000">());</span>
                        <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
                <span style="color: #FF0000">}</span>
        <span style="color: #FF0000">}</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_file_reader_close</span></span><span style="color: #990000">(</span>dbreader<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>first_name_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>phone_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>projection_schema<span style="color: #990000">);</span>

        <span style="font-style: italic"><span style="color: #9A1900">/* We don't need this schema anymore */</span></span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>person_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span></tt></pre></div></div>
<div class="paragraph"><p>When you compile and run this program, you should get the following output</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>Successfully added Hicks, Dante id=1
Successfully added Graves, Randal id=2
Successfully added Loughran, Veronica id=3
Successfully added Bree, Caitlin id=4
Successfully added Silent, Bob id=5
Successfully added ???, Jay id=6

Avro is compact. Here is the data for all 6 people.
| 02 0A 44 61 6E 74 65 0A | 48 69 63 6B 73 1C 28 35 |   ..Dante.Hicks.(5
| 35 35 29 20 31 32 33 2D | 34 35 36 37 40 04 0C 52 |   55) 123-4567@..R
| 61 6E 64 61 6C 0C 47 72 | 61 76 65 73 1C 28 35 35 |   andal.Graves.(55
| 35 29 20 31 32 33 2D 35 | 36 37 38 3C 06 10 56 65 |   5) 123-5678&lt;..Ve
| 72 6F 6E 69 63 61 10 4C | 6F 75 67 68 72 61 6E 1C |   ronica.Loughran.
| 28 35 35 35 29 20 31 32 | 33 2D 30 39 38 37 38 08 |   (555) 123-09878.
| 0E 43 61 69 74 6C 69 6E | 08 42 72 65 65 1C 28 35 |   .Caitlin.Bree.(5
| 35 35 29 20 31 32 33 2D | 32 33 32 33 36 0A 06 42 |   55) 123-23236..B
| 6F 62 0C 53 69 6C 65 6E | 74 1C 28 35 35 35 29 20 |   ob.Silent.(555)
| 31 32 33 2D 36 34 32 32 | 3A 0C 06 4A 61 79 06 3F |   123-6422:..Jay.?
| 3F 3F 1C 28 35 35 35 29 | 20 31 32 33 2D 39 31 38 |   ??.(555) 123-918
| 32 34 .. .. .. .. .. .. | .. .. .. .. .. .. .. .. |   24..............

Now let's read all the records back out
1 |           Dante |           Hicks |  (555) 123-4567 | 32
2 |          Randal |          Graves |  (555) 123-5678 | 30
3 |        Veronica |        Loughran |  (555) 123-0987 | 28
4 |         Caitlin |            Bree |  (555) 123-2323 | 27
5 |             Bob |          Silent |  (555) 123-6422 | 29
6 |             Jay |             ??? |  (555) 123-9182 | 26


Use projection to print only the First name and phone numbers
          Dante |  (555) 123-4567 |
         Randal |  (555) 123-5678 |
       Veronica |  (555) 123-0987 |
        Caitlin |  (555) 123-2323 |
            Bob |  (555) 123-6422 |
            Jay |  (555) 123-9182 |</tt></pre>
</div></div>
<div class="paragraph"><p>The <strong>Quick Stop</strong> owner was so pleased, he asked you to create a
movie database for his <strong>RST Video</strong> store.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_reference_files">9. Reference files</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_avro_h">9.1. avro.h</h3>
<div class="paragraph"><p>The <tt>avro.h</tt> header file contains the complete public API
for <tt>Avro C</tt>.  The documentation is rather sparse right now
but we&#8217;ll be adding more information soon.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-style: italic"><span style="color: #9A1900">/*</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * Licensed to the Apache Software Foundation (ASF) under one or more</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * contributor license agreements.  See the NOTICE file distributed with</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * this work for additional information regarding copyright ownership.</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * The ASF licenses this file to you under the Apache License, Version 2.0</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * (the "License"); you may not use this file except in compliance with</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * the License.  You may obtain a copy of the License at</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> *</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * </span></span><span style="text-decoration: underline"><span style="color: #0000FF">http://www.apache.org/licenses/LICENSE-2.0</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> *</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * Unless required by applicable law or agreed to in writing, software</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * distributed under the License is distributed on an "AS IS" BASIS,</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * implied.  See the License for the specific language governing</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * permissions and limitations under the License.</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> */</span></span>
<span style="font-weight: bold"><span style="color: #000080">#ifndef</span></span> AVRO_H
<span style="font-weight: bold"><span style="color: #000080">#define</span></span> AVRO_H
<span style="font-weight: bold"><span style="color: #000080">#ifdef</span></span> __cplusplus
<span style="font-weight: bold"><span style="color: #0000FF">extern</span></span> <span style="color: #FF0000">"C"</span> <span style="color: #FF0000">{</span>
<span style="font-weight: bold"><span style="color: #000080">#define</span></span> CLOSE_EXTERN <span style="color: #FF0000">}</span>
<span style="font-weight: bold"><span style="color: #000080">#else</span></span>
<span style="font-weight: bold"><span style="color: #000080">#define</span></span> CLOSE_EXTERN
<span style="font-weight: bold"><span style="color: #000080">#endif</span></span>

<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro/allocation.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro/basics.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro/consumer.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro/data.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro/errors.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro/generic.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro/io.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro/legacy.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro/platform.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro/resolver.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro/schema.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;avro/value.h&gt;</span>

CLOSE_EXTERN
<span style="font-weight: bold"><span style="color: #000080">#endif</span></span></tt></pre></div></div>
</div>
<div class="sect2">
<h3 id="_test_avro_data_c">9.2. test_avro_data.c</h3>
<div class="paragraph"><p>Another good way to learn how to encode/decode data in <tt>Avro C</tt> is
to look at the <tt>test_avro_data.c</tt> unit test.  This simple unit test
checks that all the avro types can be encoded/decoded correctly.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.5
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-style: italic"><span style="color: #9A1900">/*</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * Licensed to the Apache Software Foundation (ASF) under one or more</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * contributor license agreements.  See the NOTICE file distributed with</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * this work for additional information regarding copyright ownership.</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * The ASF licenses this file to you under the Apache License, Version 2.0</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * (the "License"); you may not use this file except in compliance with</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * the License.  You may obtain a copy of the License at</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> *</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * </span></span><span style="text-decoration: underline"><span style="color: #0000FF">http://www.apache.org/licenses/LICENSE-2.0</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> *</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * Unless required by applicable law or agreed to in writing, software</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * distributed under the License is distributed on an "AS IS" BASIS,</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * implied.  See the License for the specific language governing</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * permissions and limitations under the License.</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> */</span></span>

<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">"avro.h"</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">"avro_private.h"</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;limits.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;stdlib.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;string.h&gt;</span>
<span style="font-weight: bold"><span style="color: #000080">#include</span></span> <span style="color: #FF0000">&lt;time.h&gt;</span>

<span style="color: #009900">char</span> buf<span style="color: #990000">[</span><span style="color: #993399">4096</span><span style="color: #990000">];</span>
<span style="color: #008080">avro_reader_t</span> reader<span style="color: #990000">;</span>
<span style="color: #008080">avro_writer_t</span> writer<span style="color: #990000">;</span>

<span style="font-weight: bold"><span style="color: #0000FF">typedef</span></span> <span style="color: #009900">int</span> <span style="color: #990000">(*</span>avro_test<span style="color: #990000">)</span> <span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">);</span>

<span style="font-style: italic"><span style="color: #9A1900">/*</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * Use a custom allocator that verifies that the size that we use to</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> * free an object matches the size that we use to allocate it.</span></span>
<span style="font-style: italic"><span style="color: #9A1900"> */</span></span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">void</span> <span style="color: #990000">*</span>
<span style="font-weight: bold"><span style="color: #000000">test_allocator</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span> <span style="color: #990000">*</span>ud<span style="color: #990000">,</span> <span style="color: #009900">void</span> <span style="color: #990000">*</span>ptr<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> osize<span style="color: #990000">,</span> <span style="color: #008080">size_t</span> nsize<span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="font-weight: bold"><span style="color: #000000">AVRO_UNUSED</span></span><span style="color: #990000">(</span>ud<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">AVRO_UNUSED</span></span><span style="color: #990000">(</span>osize<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>nsize <span style="color: #990000">==</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="color: #008080">size_t</span>  <span style="color: #990000">*</span>size <span style="color: #990000">=</span> <span style="color: #990000">((</span>size_t <span style="color: #990000">*)</span> ptr<span style="color: #990000">)</span> <span style="color: #990000">-</span> <span style="color: #993399">1</span><span style="color: #990000">;</span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>osize <span style="color: #990000">!=</span> <span style="color: #990000">*</span>size<span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span>
                                <span style="color: #FF0000">"Error freeing %p:</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span>
                                <span style="color: #FF0000">"Size passed to avro_free (%"</span> PRIsz <span style="color: #FF0000">") "</span>
                                <span style="color: #FF0000">"doesn't match size passed to "</span>
                                <span style="color: #FF0000">"avro_malloc (%"</span> PRIsz <span style="color: #FF0000">")</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span>
                                ptr<span style="color: #990000">,</span> osize<span style="color: #990000">,</span> <span style="color: #990000">*</span>size<span style="color: #990000">);</span>
                        <span style="font-weight: bold"><span style="color: #000000">abort</span></span><span style="color: #990000">();</span>
                        <span style="font-style: italic"><span style="color: #9A1900">//exit(EXIT_FAILURE);</span></span>
                <span style="color: #FF0000">}</span>
                <span style="font-weight: bold"><span style="color: #000000">free</span></span><span style="color: #990000">(</span>size<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> NULL<span style="color: #990000">;</span>
        <span style="color: #FF0000">}</span> <span style="font-weight: bold"><span style="color: #0000FF">else</span></span> <span style="color: #FF0000">{</span>
                <span style="color: #008080">size_t</span>  real_size <span style="color: #990000">=</span> nsize <span style="color: #990000">+</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>size_t<span style="color: #990000">);</span>
                <span style="color: #008080">size_t</span>  <span style="color: #990000">*</span>old_size <span style="color: #990000">=</span> ptr<span style="color: #990000">?</span> <span style="color: #990000">((</span>size_t <span style="color: #990000">*)</span> ptr<span style="color: #990000">)-</span><span style="color: #993399">1</span><span style="color: #990000">:</span> NULL<span style="color: #990000">;</span>
                <span style="color: #008080">size_t</span>  <span style="color: #990000">*</span>size <span style="color: #990000">=</span> <span style="color: #990000">(</span>size_t <span style="color: #990000">*)</span> <span style="font-weight: bold"><span style="color: #000000">realloc</span></span><span style="color: #990000">(</span>old_size<span style="color: #990000">,</span> real_size<span style="color: #990000">);</span>
                <span style="color: #990000">*</span>size <span style="color: #990000">=</span> nsize<span style="color: #990000">;</span>
                <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #990000">(</span>size <span style="color: #990000">+</span> <span style="color: #993399">1</span><span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>
<span style="color: #FF0000">}</span>

<span style="color: #009900">void</span> <span style="font-weight: bold"><span style="color: #000000">init_rand</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="font-weight: bold"><span style="color: #000000">srand</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">time</span></span><span style="color: #990000">(</span>NULL<span style="color: #990000">));</span>
<span style="color: #FF0000">}</span>

<span style="color: #009900">double</span> <span style="font-weight: bold"><span style="color: #000000">rand_number</span></span><span style="color: #990000">(</span><span style="color: #009900">double</span> from<span style="color: #990000">,</span> <span style="color: #009900">double</span> to<span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #009900">double</span> range <span style="color: #990000">=</span> to <span style="color: #990000">-</span> from<span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> from <span style="color: #990000">+</span> <span style="color: #990000">((</span><span style="color: #009900">double</span><span style="color: #990000">)</span><span style="font-weight: bold"><span style="color: #000000">rand</span></span><span style="color: #990000">()</span> <span style="color: #990000">/</span> <span style="color: #990000">(</span>RAND_MAX <span style="color: #990000">+</span> <span style="color: #993399">1.0</span><span style="color: #990000">))</span> <span style="color: #990000">*</span> range<span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="color: #008080">int64_t</span> <span style="font-weight: bold"><span style="color: #000000">rand_int64</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #990000">(</span>int64_t<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #000000">rand_number</span></span><span style="color: #990000">(</span>LONG_MIN<span style="color: #990000">,</span> LONG_MAX<span style="color: #990000">);</span>
<span style="color: #FF0000">}</span>

<span style="color: #008080">int32_t</span> <span style="font-weight: bold"><span style="color: #000000">rand_int32</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #990000">(</span>int32_t<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #000000">rand_number</span></span><span style="color: #990000">(</span>INT_MIN<span style="color: #990000">,</span> INT_MAX<span style="color: #990000">);</span>
<span style="color: #FF0000">}</span>

<span style="color: #009900">void</span>
<span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_schema_t</span> writers_schema<span style="color: #990000">,</span> <span style="color: #008080">avro_datum_t</span> datum<span style="color: #990000">,</span>
                 <span style="color: #008080">avro_schema_t</span> readers_schema<span style="color: #990000">,</span> <span style="color: #008080">avro_datum_t</span> expected<span style="color: #990000">,</span> <span style="color: #009900">char</span> <span style="color: #990000">*</span>type<span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #008080">avro_datum_t</span> datum_out<span style="color: #990000">;</span>
        <span style="color: #009900">int</span> validate<span style="color: #990000">;</span>

        <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #990000">(</span>validate <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span> validate <span style="color: #990000">&lt;=</span> <span style="color: #993399">1</span><span style="color: #990000">;</span> validate<span style="color: #990000">++)</span> <span style="color: #FF0000">{</span>

                reader <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_reader_memory</span></span><span style="color: #990000">(</span>buf<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>buf<span style="color: #990000">));</span>
                writer <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_writer_memory</span></span><span style="color: #990000">(</span>buf<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>buf<span style="color: #990000">));</span>

                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(!</span>expected<span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                        expected <span style="color: #990000">=</span> datum<span style="color: #990000">;</span>
                <span style="color: #FF0000">}</span>

                <span style="font-style: italic"><span style="color: #9A1900">/* Validating read/write */</span></span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>avro_write_data
                    <span style="color: #990000">(</span>writer<span style="color: #990000">,</span> validate <span style="color: #990000">?</span> writers_schema <span style="color: #990000">:</span> NULL<span style="color: #990000">,</span> datum<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unable to write %s validate=%d</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">  %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span>
                                type<span style="color: #990000">,</span> validate<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_strerror</span></span><span style="color: #990000">());</span>
                        <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
                <span style="color: #FF0000">}</span>
                <span style="color: #008080">int64_t</span> size <span style="color: #990000">=</span>
                    <span style="font-weight: bold"><span style="color: #000000">avro_size_data</span></span><span style="color: #990000">(</span>writer<span style="color: #990000">,</span> validate <span style="color: #990000">?</span> writers_schema <span style="color: #990000">:</span> NULL<span style="color: #990000">,</span>
                                   datum<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>size <span style="color: #990000">!=</span> <span style="font-weight: bold"><span style="color: #000000">avro_writer_tell</span></span><span style="color: #990000">(</span>writer<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span>
                                <span style="color: #FF0000">"Unable to calculate size %s validate=%d "</span>
                                <span style="color: #FF0000">"(%"</span>PRId64<span style="color: #FF0000">" != %"</span>PRId64<span style="color: #FF0000">")</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">  %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span>
                                type<span style="color: #990000">,</span> validate<span style="color: #990000">,</span> size<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_writer_tell</span></span><span style="color: #990000">(</span>writer<span style="color: #990000">),</span>
                                <span style="font-weight: bold"><span style="color: #000000">avro_strerror</span></span><span style="color: #990000">());</span>
                        <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
                <span style="color: #FF0000">}</span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>avro_read_data
                    <span style="color: #990000">(</span>reader<span style="color: #990000">,</span> writers_schema<span style="color: #990000">,</span> readers_schema<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>datum_out<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unable to read %s validate=%d</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">  %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span>
                                type<span style="color: #990000">,</span> validate<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_strerror</span></span><span style="color: #990000">());</span>
                        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"  %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_strerror</span></span><span style="color: #990000">());</span>
                        <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
                <span style="color: #FF0000">}</span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(!</span><span style="font-weight: bold"><span style="color: #000000">avro_datum_equal</span></span><span style="color: #990000">(</span>expected<span style="color: #990000">,</span> datum_out<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span>
                                <span style="color: #FF0000">"Unable to encode/decode %s validate=%d</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">  %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span>
                                type<span style="color: #990000">,</span> validate<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_strerror</span></span><span style="color: #990000">());</span>
                        <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
                <span style="color: #FF0000">}</span>

                <span style="font-weight: bold"><span style="color: #000000">avro_reader_dump</span></span><span style="color: #990000">(</span>reader<span style="color: #990000">,</span> stderr<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum_out<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_reader_free</span></span><span style="color: #990000">(</span>reader<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_writer_free</span></span><span style="color: #990000">(</span>writer<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">void</span> <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span><span style="color: #008080">avro_datum_t</span> datum<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">*</span>expected<span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #009900">char</span>  <span style="color: #990000">*</span>json <span style="color: #990000">=</span> NULL<span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_to_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>json<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">strcmp</span></span><span style="color: #990000">(</span>json<span style="color: #990000">,</span> expected<span style="color: #990000">)</span> <span style="color: #990000">!=</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unexpected JSON encoding: %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span> json<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>
        <span style="font-weight: bold"><span style="color: #000000">free</span></span><span style="color: #990000">(</span>json<span style="color: #990000">);</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_string</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #009900">unsigned</span> <span style="color: #009900">int</span> i<span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span> <span style="color: #990000">*</span>strings<span style="color: #990000">[]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">{</span> <span style="color: #FF0000">"Four score and seven years ago"</span><span style="color: #990000">,</span>
                <span style="color: #FF0000">"our father brought forth on this continent"</span><span style="color: #990000">,</span>
                <span style="color: #FF0000">"a new nation"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"conceived in Liberty"</span><span style="color: #990000">,</span>
                <span style="color: #FF0000">"and dedicated to the proposition that all men are created equal."</span>
        <span style="color: #FF0000">}</span><span style="color: #990000">;</span>
        <span style="color: #008080">avro_schema_t</span> writer_schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_string</span></span><span style="color: #990000">();</span>
        <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #990000">(</span>i <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span> i <span style="color: #990000">&lt;</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>strings<span style="color: #990000">)</span> <span style="color: #990000">/</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>strings<span style="color: #990000">[</span><span style="color: #993399">0</span><span style="color: #990000">]);</span> i<span style="color: #990000">++)</span> <span style="color: #FF0000">{</span>
                <span style="color: #008080">avro_datum_t</span> datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_givestring</span></span><span style="color: #990000">(</span>strings<span style="color: #990000">[</span>i<span style="color: #990000">],</span> NULL<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"string"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="color: #008080">avro_datum_t</span>  datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_givestring</span></span><span style="color: #990000">(</span>strings<span style="color: #990000">[</span><span style="color: #993399">0</span><span style="color: #990000">],</span> NULL<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">Four score and seven years ago</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>

        <span style="font-style: italic"><span style="color: #9A1900">// The following should bork if we don't copy the string value</span></span>
        <span style="font-style: italic"><span style="color: #9A1900">// correctly (since we'll try to free a static string).</span></span>

        datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_string</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"this should be copied"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_string_set</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"also this"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_bytes</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #009900">char</span> bytes<span style="color: #990000">[]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">{</span> <span style="color: #993399">0xDE</span><span style="color: #990000">,</span> <span style="color: #993399">0xAD</span><span style="color: #990000">,</span> <span style="color: #993399">0xBE</span><span style="color: #990000">,</span> <span style="color: #993399">0xEF</span> <span style="color: #FF0000">}</span><span style="color: #990000">;</span>
        <span style="color: #008080">avro_schema_t</span> writer_schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_bytes</span></span><span style="color: #990000">();</span>
        <span style="color: #008080">avro_datum_t</span> datum<span style="color: #990000">;</span>
        <span style="color: #008080">avro_datum_t</span> expected_datum<span style="color: #990000">;</span>

        datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_givebytes</span></span><span style="color: #990000">(</span>bytes<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>bytes<span style="color: #990000">),</span> NULL<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"bytes"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"</span><span style="color: #CC33CC">\"\\</span><span style="color: #FF0000">u00de</span><span style="color: #CC33CC">\\</span><span style="color: #FF0000">u00ad</span><span style="color: #CC33CC">\\</span><span style="color: #FF0000">u00be</span><span style="color: #CC33CC">\\</span><span style="color: #FF0000">u00ef</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">);</span>

        datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_givebytes</span></span><span style="color: #990000">(</span>NULL<span style="color: #990000">,</span> <span style="color: #993399">0</span><span style="color: #990000">,</span> NULL<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_givebytes_set</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> bytes<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>bytes<span style="color: #990000">),</span> NULL<span style="color: #990000">);</span>
        expected_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_givebytes</span></span><span style="color: #990000">(</span>bytes<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>bytes<span style="color: #990000">),</span> NULL<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(!</span><span style="font-weight: bold"><span style="color: #000000">avro_datum_equal</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> expected_datum<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span>
                        <span style="color: #FF0000">"Expected equal bytes instances.</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>expected_datum<span style="color: #990000">);</span>

        <span style="font-style: italic"><span style="color: #9A1900">// The following should bork if we don't copy the bytes value</span></span>
        <span style="font-style: italic"><span style="color: #9A1900">// correctly (since we'll try to free a static string).</span></span>

        datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_bytes</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"original"</span><span style="color: #990000">,</span> <span style="color: #993399">8</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_bytes_set</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"alsothis"</span><span style="color: #990000">,</span> <span style="color: #993399">8</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_int32</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #009900">int</span> i<span style="color: #990000">;</span>
        <span style="color: #008080">avro_schema_t</span> writer_schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_int</span></span><span style="color: #990000">();</span>
        <span style="color: #008080">avro_schema_t</span> long_schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_long</span></span><span style="color: #990000">();</span>
        <span style="color: #008080">avro_schema_t</span> float_schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_float</span></span><span style="color: #990000">();</span>
        <span style="color: #008080">avro_schema_t</span> double_schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_double</span></span><span style="color: #990000">();</span>
        <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #990000">(</span>i <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span> i <span style="color: #990000">&lt;</span> <span style="color: #993399">100</span><span style="color: #990000">;</span> i<span style="color: #990000">++)</span> <span style="color: #FF0000">{</span>
                <span style="color: #008080">int32_t</span>  value <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">rand_int32</span></span><span style="color: #990000">();</span>
                <span style="color: #008080">avro_datum_t</span> datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_int32</span></span><span style="color: #990000">(</span>value<span style="color: #990000">);</span>
                <span style="color: #008080">avro_datum_t</span> long_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_int64</span></span><span style="color: #990000">(</span>value<span style="color: #990000">);</span>
                <span style="color: #008080">avro_datum_t</span> float_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_float</span></span><span style="color: #990000">(</span>value<span style="color: #990000">);</span>
                <span style="color: #008080">avro_datum_t</span> double_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_double</span></span><span style="color: #990000">(</span>value<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"int"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span>
                                 long_schema<span style="color: #990000">,</span> long_datum<span style="color: #990000">,</span> <span style="color: #FF0000">"int-&gt;long"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span>
                                 float_schema<span style="color: #990000">,</span> float_datum<span style="color: #990000">,</span> <span style="color: #FF0000">"int-&gt;float"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span>
                                 double_schema<span style="color: #990000">,</span> double_datum<span style="color: #990000">,</span> <span style="color: #FF0000">"int-&gt;double"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>long_datum<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>float_datum<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>double_datum<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="color: #008080">avro_datum_t</span>  datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_int32</span></span><span style="color: #990000">(</span><span style="color: #993399">10000</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"10000"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>long_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>float_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>double_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_int64</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #009900">int</span> i<span style="color: #990000">;</span>
        <span style="color: #008080">avro_schema_t</span> writer_schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_long</span></span><span style="color: #990000">();</span>
        <span style="color: #008080">avro_schema_t</span> float_schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_float</span></span><span style="color: #990000">();</span>
        <span style="color: #008080">avro_schema_t</span> double_schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_double</span></span><span style="color: #990000">();</span>
        <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #990000">(</span>i <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span> i <span style="color: #990000">&lt;</span> <span style="color: #993399">100</span><span style="color: #990000">;</span> i<span style="color: #990000">++)</span> <span style="color: #FF0000">{</span>
                <span style="color: #008080">int64_t</span>  value <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">rand_int64</span></span><span style="color: #990000">();</span>
                <span style="color: #008080">avro_datum_t</span> datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_int64</span></span><span style="color: #990000">(</span>value<span style="color: #990000">);</span>
                <span style="color: #008080">avro_datum_t</span> float_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_float</span></span><span style="color: #990000">(</span>value<span style="color: #990000">);</span>
                <span style="color: #008080">avro_datum_t</span> double_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_double</span></span><span style="color: #990000">(</span>value<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"long"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span>
                                 float_schema<span style="color: #990000">,</span> float_datum<span style="color: #990000">,</span> <span style="color: #FF0000">"long-&gt;float"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span>
                                 double_schema<span style="color: #990000">,</span> double_datum<span style="color: #990000">,</span> <span style="color: #FF0000">"long-&gt;double"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>float_datum<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>double_datum<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="color: #008080">avro_datum_t</span>  datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_int64</span></span><span style="color: #990000">(</span><span style="color: #993399">10000</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"10000"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>writer_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>float_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>double_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_double</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #009900">int</span> i<span style="color: #990000">;</span>
        <span style="color: #008080">avro_schema_t</span> schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_double</span></span><span style="color: #990000">();</span>
        <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #990000">(</span>i <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span> i <span style="color: #990000">&lt;</span> <span style="color: #993399">100</span><span style="color: #990000">;</span> i<span style="color: #990000">++)</span> <span style="color: #FF0000">{</span>
                <span style="color: #008080">avro_datum_t</span> datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_double</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">rand_number</span></span><span style="color: #990000">(-</span><span style="color: #993399">1.0E10</span><span style="color: #990000">,</span> <span style="color: #993399">1.0E10</span><span style="color: #990000">));</span>
                <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"double"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="color: #008080">avro_datum_t</span>  datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_double</span></span><span style="color: #990000">(</span><span style="color: #993399">2000.0</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"2000.0"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_float</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #009900">int</span> i<span style="color: #990000">;</span>
        <span style="color: #008080">avro_schema_t</span> schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_float</span></span><span style="color: #990000">();</span>
        <span style="color: #008080">avro_schema_t</span> double_schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_double</span></span><span style="color: #990000">();</span>
        <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #990000">(</span>i <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span> i <span style="color: #990000">&lt;</span> <span style="color: #993399">100</span><span style="color: #990000">;</span> i<span style="color: #990000">++)</span> <span style="color: #FF0000">{</span>
                <span style="color: #009900">float</span>  value <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">rand_number</span></span><span style="color: #990000">(-</span><span style="color: #993399">1.0E10</span><span style="color: #990000">,</span> <span style="color: #993399">1.0E10</span><span style="color: #990000">);</span>
                <span style="color: #008080">avro_datum_t</span> datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_float</span></span><span style="color: #990000">(</span>value<span style="color: #990000">);</span>
                <span style="color: #008080">avro_datum_t</span> double_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_double</span></span><span style="color: #990000">(</span>value<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"float"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span>
                                 double_schema<span style="color: #990000">,</span> double_datum<span style="color: #990000">,</span> <span style="color: #FF0000">"float-&gt;double"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>double_datum<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="color: #008080">avro_datum_t</span>  datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_float</span></span><span style="color: #990000">(</span><span style="color: #993399">2000.0</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"2000.0"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>double_schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_boolean</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #009900">int</span> i<span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span>  <span style="color: #990000">*</span>expected_json<span style="color: #990000">[]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">{</span> <span style="color: #FF0000">"false"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"true"</span> <span style="color: #FF0000">}</span><span style="color: #990000">;</span>
        <span style="color: #008080">avro_schema_t</span> schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_boolean</span></span><span style="color: #990000">();</span>
        <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #990000">(</span>i <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span> i <span style="color: #990000">&lt;=</span> <span style="color: #993399">1</span><span style="color: #990000">;</span> i<span style="color: #990000">++)</span> <span style="color: #FF0000">{</span>
                <span style="color: #008080">avro_datum_t</span> datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_boolean</span></span><span style="color: #990000">(</span>i<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"boolean"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> expected_json<span style="color: #990000">[</span>i<span style="color: #990000">]);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_null</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #008080">avro_schema_t</span> schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_null</span></span><span style="color: #990000">();</span>
        <span style="color: #008080">avro_datum_t</span> datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_null</span></span><span style="color: #990000">();</span>
        <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"null"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"null"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_record</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #008080">avro_schema_t</span> schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_record</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"person"</span><span style="color: #990000">,</span> NULL<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_record_field_append</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> <span style="color: #FF0000">"name"</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_string</span></span><span style="color: #990000">());</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_record_field_append</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> <span style="color: #FF0000">"age"</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_int</span></span><span style="color: #990000">());</span>

        <span style="color: #008080">avro_datum_t</span> datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_record</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="color: #008080">avro_datum_t</span> name_datum<span style="color: #990000">,</span> age_datum<span style="color: #990000">;</span>

        name_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_givestring</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"Joseph Campbell"</span><span style="color: #990000">,</span> NULL<span style="color: #990000">);</span>
        age_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_int32</span></span><span style="color: #990000">(</span><span style="color: #993399">83</span><span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_record_set</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"name"</span><span style="color: #990000">,</span> name_datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_record_set</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"age"</span><span style="color: #990000">,</span> age_datum<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"record"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"{</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">name</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">Joseph Campbell</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">age</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: 83}"</span><span style="color: #990000">);</span>

        <span style="color: #009900">int</span>  rc<span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_record_set_field_value</span></span><span style="color: #990000">(</span>rc<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> int32<span style="color: #990000">,</span> <span style="color: #FF0000">"age"</span><span style="color: #990000">,</span> <span style="color: #993399">104</span><span style="color: #990000">);</span>

        <span style="color: #008080">int32_t</span>  age <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_record_get_field_value</span></span><span style="color: #990000">(</span>rc<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> int32<span style="color: #990000">,</span> <span style="color: #FF0000">"age"</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>age<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>age <span style="color: #990000">!=</span> <span style="color: #993399">104</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Incorrect age value</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>name_datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>age_datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_nested_record</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span>  <span style="color: #990000">*</span>json <span style="color: #990000">=</span>
                <span style="color: #FF0000">"{"</span>
                <span style="color: #FF0000">"  </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">type</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">record</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">,"</span>
                <span style="color: #FF0000">"  </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">name</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">list</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">,"</span>
                <span style="color: #FF0000">"  </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">fields</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: ["</span>
                <span style="color: #FF0000">"    { </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">name</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">x</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">type</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">int</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000"> },"</span>
                <span style="color: #FF0000">"    { </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">name</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">y</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">type</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">int</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000"> },"</span>
                <span style="color: #FF0000">"    { </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">name</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">next</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">type</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: [</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">null</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">,</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">list</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">]}"</span>
                <span style="color: #FF0000">"  ]"</span>
                <span style="color: #FF0000">"}"</span><span style="color: #990000">;</span>

        <span style="color: #009900">int</span>  rval<span style="color: #990000">;</span>

        <span style="color: #008080">avro_schema_t</span> schema <span style="color: #990000">=</span> NULL<span style="color: #990000">;</span>
        <span style="color: #008080">avro_schema_error_t</span> error<span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_from_json</span></span><span style="color: #990000">(</span>json<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">strlen</span></span><span style="color: #990000">(</span>json<span style="color: #990000">),</span> <span style="color: #990000">&amp;</span>schema<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>error<span style="color: #990000">);</span>

        <span style="color: #008080">avro_datum_t</span>  head <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_datum_from_schema</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_record_set_field_value</span></span><span style="color: #990000">(</span>rval<span style="color: #990000">,</span> head<span style="color: #990000">,</span> int32<span style="color: #990000">,</span> <span style="color: #FF0000">"x"</span><span style="color: #990000">,</span> <span style="color: #993399">10</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_record_set_field_value</span></span><span style="color: #990000">(</span>rval<span style="color: #990000">,</span> head<span style="color: #990000">,</span> int32<span style="color: #990000">,</span> <span style="color: #FF0000">"y"</span><span style="color: #990000">,</span> <span style="color: #993399">10</span><span style="color: #990000">);</span>

        <span style="color: #008080">avro_datum_t</span>  next <span style="color: #990000">=</span> NULL<span style="color: #990000">;</span>
        <span style="color: #008080">avro_datum_t</span>  tail <span style="color: #990000">=</span> NULL<span style="color: #990000">;</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_record_get</span></span><span style="color: #990000">(</span>head<span style="color: #990000">,</span> <span style="color: #FF0000">"next"</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>next<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_union_set_discriminant</span></span><span style="color: #990000">(</span>next<span style="color: #990000">,</span> <span style="color: #993399">1</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>tail<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_record_set_field_value</span></span><span style="color: #990000">(</span>rval<span style="color: #990000">,</span> tail<span style="color: #990000">,</span> int32<span style="color: #990000">,</span> <span style="color: #FF0000">"x"</span><span style="color: #990000">,</span> <span style="color: #993399">20</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_record_set_field_value</span></span><span style="color: #990000">(</span>rval<span style="color: #990000">,</span> tail<span style="color: #990000">,</span> int32<span style="color: #990000">,</span> <span style="color: #FF0000">"y"</span><span style="color: #990000">,</span> <span style="color: #993399">20</span><span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_record_get</span></span><span style="color: #990000">(</span>tail<span style="color: #990000">,</span> <span style="color: #FF0000">"next"</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>next<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_union_set_discriminant</span></span><span style="color: #990000">(</span>next<span style="color: #990000">,</span> <span style="color: #993399">0</span><span style="color: #990000">,</span> NULL<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> head<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"nested record"</span><span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>head<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_enum</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="font-weight: bold"><span style="color: #0000FF">enum</span></span> avro_languages <span style="color: #FF0000">{</span>
                AVRO_C<span style="color: #990000">,</span>
                AVRO_CPP<span style="color: #990000">,</span>
                AVRO_PYTHON<span style="color: #990000">,</span>
                AVRO_RUBY<span style="color: #990000">,</span>
                AVRO_JAVA
        <span style="color: #FF0000">}</span><span style="color: #990000">;</span>
        <span style="color: #008080">avro_schema_t</span> schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_enum</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"language"</span><span style="color: #990000">);</span>
        <span style="color: #008080">avro_datum_t</span> datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_enum</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> AVRO_C<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_schema_enum_symbol_append</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> <span style="color: #FF0000">"C"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_enum_symbol_append</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> <span style="color: #FF0000">"C++"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_enum_symbol_append</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> <span style="color: #FF0000">"Python"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_enum_symbol_append</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> <span style="color: #FF0000">"Ruby"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_enum_symbol_append</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> <span style="color: #FF0000">"Java"</span><span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_enum_get</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">)</span> <span style="color: #990000">!=</span> AVRO_C<span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unexpected enum value AVRO_C</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">strcmp</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_enum_get_name</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">),</span> <span style="color: #FF0000">"C"</span><span style="color: #990000">)</span> <span style="color: #990000">!=</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unexpected enum value name C</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"enum"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">C</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_enum_set</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> AVRO_CPP<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">strcmp</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_enum_get_name</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">),</span> <span style="color: #FF0000">"C++"</span><span style="color: #990000">)</span> <span style="color: #990000">!=</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unexpected enum value name C++</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"enum"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">C++</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_enum_set_name</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"Python"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_enum_get</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">)</span> <span style="color: #990000">!=</span> AVRO_PYTHON<span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unexpected enum value AVRO_PYTHON</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"enum"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">Python</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_array</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #009900">int</span> i<span style="color: #990000">,</span> rval<span style="color: #990000">;</span>
        <span style="color: #008080">avro_schema_t</span> schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_array</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_schema_int</span></span><span style="color: #990000">());</span>
        <span style="color: #008080">avro_datum_t</span> datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_array</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #990000">(</span>i <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span> i <span style="color: #990000">&lt;</span> <span style="color: #993399">10</span><span style="color: #990000">;</span> i<span style="color: #990000">++)</span> <span style="color: #FF0000">{</span>
                <span style="color: #008080">avro_datum_t</span> i32_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_int32</span></span><span style="color: #990000">(</span>i<span style="color: #990000">);</span>
                rval <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_array_append_datum</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> i32_datum<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>i32_datum<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>rval<span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
                <span style="color: #FF0000">}</span>
        <span style="color: #FF0000">}</span>

        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_array_size</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">)</span> <span style="color: #990000">!=</span> <span style="color: #993399">10</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unexpected array size"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"array"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_map</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #008080">avro_schema_t</span> schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_map</span></span><span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_schema_long</span></span><span style="color: #990000">());</span>
        <span style="color: #008080">avro_datum_t</span> datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_map</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="color: #008080">int64_t</span> i <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
        <span style="color: #009900">char</span> <span style="color: #990000">*</span>nums<span style="color: #990000">[]</span> <span style="color: #990000">=</span>
            <span style="color: #FF0000">{</span> <span style="color: #FF0000">"zero"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"one"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"two"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"three"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"four"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"five"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"six"</span><span style="color: #990000">,</span> NULL <span style="color: #FF0000">}</span><span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #0000FF">while</span></span> <span style="color: #990000">(</span>nums<span style="color: #990000">[</span>i<span style="color: #990000">])</span> <span style="color: #FF0000">{</span>
                <span style="color: #008080">avro_datum_t</span> i_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_int64</span></span><span style="color: #990000">(</span>i<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_map_set</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> nums<span style="color: #990000">[</span>i<span style="color: #990000">],</span> i_datum<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>i_datum<span style="color: #990000">);</span>
                i<span style="color: #990000">++;</span>
        <span style="color: #FF0000">}</span>

        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_array_size</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">)</span> <span style="color: #990000">!=</span> <span style="color: #993399">7</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unexpected map size</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="color: #008080">avro_datum_t</span> value<span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #0000FF">const</span></span> <span style="color: #009900">char</span>  <span style="color: #990000">*</span>key<span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_map_get_key</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #993399">2</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>key<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_map_get</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> key<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>value<span style="color: #990000">);</span>
        <span style="color: #008080">int64_t</span>  val<span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_int64_get</span></span><span style="color: #990000">(</span>value<span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>val<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>val <span style="color: #990000">!=</span> <span style="color: #993399">2</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unexpected map value 2</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="color: #009900">int</span>  index<span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_map_get_index</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"two"</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>index<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Can't get index for key </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">two</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: %s</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span>
                        <span style="font-weight: bold"><span style="color: #000000">avro_strerror</span></span><span style="color: #990000">());</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>index <span style="color: #990000">!=</span> <span style="color: #993399">2</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unexpected index for key </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">two</span><span style="color: #CC33CC">\"\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(!</span><span style="font-weight: bold"><span style="color: #000000">avro_map_get_index</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"foobar"</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>index<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unexpected index for key </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">foobar</span><span style="color: #CC33CC">\"\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"map"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span>
                  <span style="color: #FF0000">"{</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">zero</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: 0, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">one</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: 1, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">two</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: 2, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">three</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: 3, "</span>
                  <span style="color: #FF0000">"</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">four</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: 4, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">five</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: 5, </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">six</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: 6}"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_union</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #008080">avro_schema_t</span> schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_union</span></span><span style="color: #990000">();</span>
        <span style="color: #008080">avro_datum_t</span> union_datum<span style="color: #990000">;</span>
        <span style="color: #008080">avro_datum_t</span> datum<span style="color: #990000">;</span>
        <span style="color: #008080">avro_datum_t</span> union_datum1<span style="color: #990000">;</span>
        <span style="color: #008080">avro_datum_t</span> datum1<span style="color: #990000">;</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_schema_union_append</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_string</span></span><span style="color: #990000">());</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_union_append</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_int</span></span><span style="color: #990000">());</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_union_append</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_null</span></span><span style="color: #990000">());</span>

        datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_givestring</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"Follow your bliss."</span><span style="color: #990000">,</span> NULL<span style="color: #990000">);</span>
        union_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_union</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> <span style="color: #993399">0</span><span style="color: #990000">,</span> datum<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_union_discriminant</span></span><span style="color: #990000">(</span>union_datum<span style="color: #990000">)</span> <span style="color: #990000">!=</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unexpected union discriminant</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #000000">avro_union_current_branch</span></span><span style="color: #990000">(</span>union_datum<span style="color: #990000">)</span> <span style="color: #990000">!=</span> datum<span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Unexpected union branch datum</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        union_datum1 <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_datum_from_schema</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_union_set_discriminant</span></span><span style="color: #990000">(</span>union_datum1<span style="color: #990000">,</span> <span style="color: #993399">0</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>datum1<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_givestring_set</span></span><span style="color: #990000">(</span>datum1<span style="color: #990000">,</span> <span style="color: #FF0000">"Follow your bliss."</span><span style="color: #990000">,</span> NULL<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(!</span><span style="font-weight: bold"><span style="color: #000000">avro_datum_equal</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> datum1<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"Union values should be equal</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>

        <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> union_datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"union"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>union_datum<span style="color: #990000">,</span> <span style="color: #FF0000">"{</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">string</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">: </span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">Follow your bliss.</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">}"</span><span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_union_set_discriminant</span></span><span style="color: #990000">(</span>union_datum<span style="color: #990000">,</span> <span style="color: #993399">2</span><span style="color: #990000">,</span> <span style="color: #990000">&amp;</span>datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>union_datum<span style="color: #990000">,</span> <span style="color: #FF0000">"null"</span><span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>union_datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>union_datum1<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">test_fixed</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="color: #009900">char</span> bytes<span style="color: #990000">[]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">{</span> <span style="color: #993399">0xD</span><span style="color: #990000">,</span> <span style="color: #993399">0xA</span><span style="color: #990000">,</span> <span style="color: #993399">0xD</span><span style="color: #990000">,</span> <span style="color: #993399">0xA</span><span style="color: #990000">,</span> <span style="color: #993399">0xB</span><span style="color: #990000">,</span> <span style="color: #993399">0xA</span><span style="color: #990000">,</span> <span style="color: #993399">0xB</span><span style="color: #990000">,</span> <span style="color: #993399">0xA</span> <span style="color: #FF0000">}</span><span style="color: #990000">;</span>
        <span style="color: #008080">avro_schema_t</span> schema <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_schema_fixed</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"msg"</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>bytes<span style="color: #990000">));</span>
        <span style="color: #008080">avro_datum_t</span> datum<span style="color: #990000">;</span>
        <span style="color: #008080">avro_datum_t</span> expected_datum<span style="color: #990000">;</span>

        datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_givefixed</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> bytes<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>bytes<span style="color: #990000">),</span> NULL<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">write_read_check</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> datum<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="color: #FF0000">"fixed"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">test_json</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"</span><span style="color: #CC33CC">\"\\</span><span style="color: #FF0000">r</span><span style="color: #CC33CC">\\</span><span style="color: #FF0000">n</span><span style="color: #CC33CC">\\</span><span style="color: #FF0000">r</span><span style="color: #CC33CC">\\</span><span style="color: #FF0000">n</span><span style="color: #CC33CC">\\</span><span style="color: #FF0000">u000b</span><span style="color: #CC33CC">\\</span><span style="color: #FF0000">n</span><span style="color: #CC33CC">\\</span><span style="color: #FF0000">u000b</span><span style="color: #CC33CC">\\</span><span style="color: #FF0000">n</span><span style="color: #CC33CC">\"</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>

        datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_givefixed</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> NULL<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>bytes<span style="color: #990000">),</span> NULL<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_givefixed_set</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> bytes<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>bytes<span style="color: #990000">),</span> NULL<span style="color: #990000">);</span>
        expected_datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_givefixed</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> bytes<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>bytes<span style="color: #990000">),</span> NULL<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(!</span><span style="font-weight: bold"><span style="color: #000000">avro_datum_equal</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> expected_datum<span style="color: #990000">))</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span>
                        <span style="color: #FF0000">"Expected equal fixed instances.</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #000000">exit</span></span><span style="color: #990000">(</span>EXIT_FAILURE<span style="color: #990000">);</span>
        <span style="color: #FF0000">}</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>expected_datum<span style="color: #990000">);</span>

        <span style="font-style: italic"><span style="color: #9A1900">// The following should bork if we don't copy the fixed value</span></span>
        <span style="font-style: italic"><span style="color: #9A1900">// correctly (since we'll try to free a static string).</span></span>

        datum <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">avro_fixed</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">,</span> <span style="color: #FF0000">"original"</span><span style="color: #990000">,</span> <span style="color: #993399">8</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_fixed_set</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">,</span> <span style="color: #FF0000">"alsothis"</span><span style="color: #990000">,</span> <span style="color: #993399">8</span><span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_datum_decref</span></span><span style="color: #990000">(</span>datum<span style="color: #990000">);</span>

        <span style="font-weight: bold"><span style="color: #000000">avro_schema_decref</span></span><span style="color: #990000">(</span>schema<span style="color: #990000">);</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> <span style="color: #993399">0</span><span style="color: #990000">;</span>
<span style="color: #FF0000">}</span>

<span style="color: #009900">int</span> <span style="font-weight: bold"><span style="color: #000000">main</span></span><span style="color: #990000">(</span><span style="color: #009900">void</span><span style="color: #990000">)</span>
<span style="color: #FF0000">{</span>
        <span style="font-weight: bold"><span style="color: #000000">avro_set_allocator</span></span><span style="color: #990000">(</span>test_allocator<span style="color: #990000">,</span> NULL<span style="color: #990000">);</span>

        <span style="color: #009900">unsigned</span> <span style="color: #009900">int</span> i<span style="color: #990000">;</span>
        <span style="font-weight: bold"><span style="color: #0000FF">struct</span></span> <span style="color: #008080">avro_tests</span> <span style="color: #FF0000">{</span>
                <span style="color: #009900">char</span> <span style="color: #990000">*</span>name<span style="color: #990000">;</span>
                <span style="color: #008080">avro_test</span> func<span style="color: #990000">;</span>
        <span style="color: #FF0000">}</span> tests<span style="color: #990000">[]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"string"</span><span style="color: #990000">,</span> test_string<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"bytes"</span><span style="color: #990000">,</span> test_bytes<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"int"</span><span style="color: #990000">,</span> test_int32<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"long"</span><span style="color: #990000">,</span> test_int64<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"float"</span><span style="color: #990000">,</span> test_float<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"double"</span><span style="color: #990000">,</span> test_double<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"boolean"</span><span style="color: #990000">,</span> test_boolean<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"null"</span><span style="color: #990000">,</span> test_null<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"record"</span><span style="color: #990000">,</span> test_record<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"nested_record"</span><span style="color: #990000">,</span> test_nested_record<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"enum"</span><span style="color: #990000">,</span> test_enum<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"array"</span><span style="color: #990000">,</span> test_array<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"map"</span><span style="color: #990000">,</span> test_map<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"fixed"</span><span style="color: #990000">,</span> test_fixed<span style="color: #FF0000">}</span><span style="color: #990000">,</span> <span style="color: #FF0000">{</span>
                <span style="color: #FF0000">"union"</span><span style="color: #990000">,</span> test_union<span style="color: #FF0000">}</span>
        <span style="color: #FF0000">}</span><span style="color: #990000">;</span>

        <span style="font-weight: bold"><span style="color: #000000">init_rand</span></span><span style="color: #990000">();</span>
        <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> <span style="color: #990000">(</span>i <span style="color: #990000">=</span> <span style="color: #993399">0</span><span style="color: #990000">;</span> i <span style="color: #990000">&lt;</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>tests<span style="color: #990000">)</span> <span style="color: #990000">/</span> <span style="font-weight: bold"><span style="color: #0000FF">sizeof</span></span><span style="color: #990000">(</span>tests<span style="color: #990000">[</span><span style="color: #993399">0</span><span style="color: #990000">]);</span> i<span style="color: #990000">++)</span> <span style="color: #FF0000">{</span>
                <span style="font-weight: bold"><span style="color: #0000FF">struct</span></span> <span style="color: #008080">avro_tests</span> <span style="color: #990000">*</span>test <span style="color: #990000">=</span> tests <span style="color: #990000">+</span> i<span style="color: #990000">;</span>
                <span style="font-weight: bold"><span style="color: #000000">fprintf</span></span><span style="color: #990000">(</span>stderr<span style="color: #990000">,</span> <span style="color: #FF0000">"**** Running %s tests ****</span><span style="color: #CC33CC">\n</span><span style="color: #FF0000">"</span><span style="color: #990000">,</span> test<span style="color: #990000">-&gt;</span>name<span style="color: #990000">);</span>
                <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">(</span>test<span style="color: #990000">-&gt;</span><span style="font-weight: bold"><span style="color: #000000">func</span></span><span style="color: #990000">()</span> <span style="color: #990000">!=</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #FF0000">{</span>
                        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> EXIT_FAILURE<span style="color: #990000">;</span>
                <span style="color: #FF0000">}</span>
        <span style="color: #FF0000">}</span>
        <span style="font-weight: bold"><span style="color: #0000FF">return</span></span> EXIT_SUCCESS<span style="color: #990000">;</span>
<span style="color: #FF0000">}</span></tt></pre></div></div>
</div>
</div>
</div>
</div>
<div id="footnotes"><hr /></div>
<div id="footer">
<div id="footer-text">
Last updated 2012-09-17 17:34:37 PDT
</div>
</div>
</body>
</html>
